我想停止播放音频,但不仅要暂停它,而且我还希望如果我重新打开它,它会从第一个开始播放,而不是我停止播放的中间部分。
最佳答案
您已经尝试了什么?这应该可以满足您的需求。
function stop(el){
el.pause(); // Stop playing
el.currentTime = 0; // Reset time
}
这是一个工作示例,其中指定了 id
而不是 element
function stop(elementId) {
var el = document.getElementById(elementId);
el.pause(); // Stop playing
el.currentTime = 0; // Reset time
}
<audio id="myAudio" controls>
<source src="http://ccrma.stanford.edu/~jos/mp3/viola.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<br/><br/>
<button onclick="stop('myAudio')">Stop playing</button>
关于jquery - 如何停止使用 jquery 播放音频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55236619/