我编写了以下代码,每次打开新页面时,音乐都会从头开始。请帮帮我。
<body>
<embed src="2.mp3" autostart="true" loop="infinite"
width="2" height="0">
</embed>
---
---
</body>
答案 0 :(得分:1)
嵌入音频标签并设置自动播放和循环属性。试试这个:
<audio src="http://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" style="display: none" autoplay loop>
答案 1 :(得分:1)
以下将继续播放背景音乐:
<audio src="2.mp3" autoplay loop></audio>
答案 2 :(得分:0)
全部谢谢。我找到了它的代码。
<script>
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 {
setCookie('timePlayed', song.currentTime);
}
}
setInterval(update,1000);
</script>
<audio preload="auto" src="http://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" loop="true" autobuffer>
</audio>