如何在HTML中使用音乐

时间:2018-10-09 07:25:23

标签: html html5-audio

我正在尝试创建html并在所有页面中使用音乐,而不是从头开始?

我使用html的常规代码

<audio controls loop>
   <source src="dragonball.mp3" type="audio/mpg">
   <source src="dragonball.mp3" type="audio/mpeg">

我还使用了一种javascript

function setCookie(c_name,value,exdays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
    {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x==c_name)
        {
            return unescape(y);
        }
    }
}

var song = document.getElementsByTagName('audio')[0];
var played = false;
var tillPlayed = getCookie('timePlayed');
function update()
{
    if(!played) {
        if(tillPlayed) {
            song.currentTime = tillPlayed;
            song.play();
            played = true;
        }
        else {
            song.play();
            played = true;
        }
    }
    else {
        set Cookie('time Played', song. current-time);
    }
}
setInterval(update,1000);`$`

从头开始,也许有人知道我做错了吗?

0 个答案:

没有答案