您的位置:首页 > Web前端 > HTML5

HTML5做的音频播放器,可以动态的更换音频文件的内容

2015-08-27 11:24 501 查看
在做一个播放按钮时突然用到了这个技术,具体还是蛮简单的,一看就会,就是那个音频文件的src属性动态赋值的时候花了点时间。看代码吧!

function playOrPaused(obj) {

            

            var url = "f:/lrh.mp3";

            //alert(url);

            var audio = document.getElementById("audio");

            if (audio) {

            }

            else {

                var board = document.getElementById("_button");

                var a2 = document.createElement("audio");

                a2.setAttribute("src", url);

                a2.setAttribute("controls", "controls");

                a2.setAttribute("id", "audio");

                audio = board.appendChild(a2);

            }

            if (audio.paused) {

                audio.play();

                document.getElementById("btn").value = "暂停";

                return;

            } else {

                audio.pause();

                document.getElementById("btn").value = "播放";

            }

        }

<body>

    <form id="form1" runat="server">

        <div>

            <div id="_button" runat="server" style="width: 100%; height: 40px;">

                <input id="btn" type="button" value="播放" style="height: 30px; width: 80px; margin-top: 2px" onclick="playOrPaused(this);" />

            </div>

            </div>

    </form>

</body>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息