音乐播放

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<audio  controls>
    <source src=""  type="audio/mp3">
</audio>
<p>
    <select onclick="getinfo()" name="sel" id="sel" size="8" style="width: 300px;">
        <option>薛之谦 - 意外.mp3</option>
        <option>朴树 - 平凡之路.mp3</option>
        <option>jiaru.mp3</option>
        <option>yinweiwoaini.mp3</option>
        <option>张学友 - 一千个伤心的理由.mp3</option>
        <option>心愿.mp3</option>
        <option>高梨康治 (たかなし やすはる) - 邪心を焼く炎 (焚烧邪心的火焰).mp3</option>
    </select>
    <input type="button" onclick="playall()" value="全部依次循环播放"/>
</p>
<script>
    var num=0;


    function playall(){
        if(num>=document.getElementById("sel").options.length)
            num=0;
        var au=document.getElementsByTagName("audio")[0];
        au.src="mp3/"+document.getElementById("sel").options[num].text;
        num++;
        au.load();
        au.play();
    }


    //    document.getElementsByTagName("audio")[0].onended=playall;
    document.getElementsByTagName("audio")[0].addEventListener("ended", playall);


    function getinfo(){
//        document.getElementById("sel").value;


//        alert(document.getElementsByTagName("audio")[0].getElementsByTagName("source")[0].src)
        document.getElementsByTagName("audio")[0].getElementsByTagName("source")[0].src = "mp3/"+document.getElementById("sel").value;
        document.getElementsByTagName("audio")[0].load();
        document.getElementsByTagName("audio")[0].play();
    }
</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值