作者:刘洁05_836 | 来源:互联网 | 2023-05-21 14:57
我想检测音频是否正在播放,如果是,则不允许再播放它直到完成.播放相同的音频两次会导致音频错误.
HTML
Play Press two times
使用Javascript:
function play() {
var sound = new Audio('https://mfaucet.com/images/notification2.mp3');
console.log('Paused: ' + sound.paused);
console.log('Ended: ' + sound.ended);
console.log('Current time: ' + sound.currentTime);
sound.play();
console.log('-----------------');
console.log('Paused: ' + sound.paused);
console.log('Ended: ' + sound.ended);
console.log('Current time: ' + sound.currentTime);
console.log('-----------------------------');
}
在线:http://jsbin.com/hageko/1/
谢谢.
1> 小智..: 这应该工作:
var sound = new Audio('https://mfaucet.com/images/notification2.mp3');
function play(sound) {
if(!sound.paused) sound.pause();
sound.currentTime = 0;
sound.play();
}
Play Press two times