使用currentTime时出现问题;我下面的代码仅适用于Google Chrome。我尝试了其他方法,但没有结果。我错过了什么吗?
function togglePlay(tid, tname) {
if (myAudio.src == 'http://yoursite.com' + tname) {
tem = myAudio.currentTime;
} else {
tem = 0;
}
myAudio.src = tname;
rid = tid;
if (isPlaying) {
myAudio.currentTime = tem;
myAudio.pause();
isPlaying = false;
document.getElementById(tid).className = "start";
} else {
myAudio.currentTime = tem;
myAudio.play();
isPlaying = true;
document.getElementById(tid).className = "stop";
}
};
我自己解决了这个问题。错误在于排除if myAudio.src = tname;。 rid = tid;
function togglePlay(tid, tname) {
if (myAudio.src == 'http://yoursite.com' + tname) {
tem = myAudio.currentTime;
} else {
tem = 0;
myAudio.src = tname;
rid = tid;
}
if (isPlaying) {
myAudio.currentTime = tem;
myAudio.pause();
isPlaying = false;
document.getElementById(tid).className = "start";
} else {
myAudio.currentTime = tem;
myAudio.play();
isPlaying = true;
document.getElementById(tid).className = "stop";
}
};