HTML5音频控制停止按钮(而不是暂停) [英] HTML5 audio control stop button (as opposed to pause)
问题描述
我已经绝对无处不在(我认为),似乎找不到一种方法来调用html5音频控制器中的停止事件。我的音频控制器有一个播放列表,其中每个轨道将播放,当选择或循环通过每个轨道到下一个。还有一个下一个按钮。
I've been absolutely everywhere (I think) and can't seem to find a way to call a stop event in an html5 audio controller. My audio controller has a playlist where each track will play when selected or cycle through each track to the next. There's also a next button which works.
我的播放/暂停按钮看起来像这样:
My play/pause button looks like this:
` function playPause() {
var audioPlayer = document.getElementsByTagName('audio')[0];
if(audioPlayer!=undefined) {
if (audioPlayer.paused) {
audioPlayer.play();
} else {
audioPlayer.pause();
}
} else {
loadPlayer();
}
}
`
按钮,停止音频并返回到当前正在播放的曲目的开头。
I need a "Stop" button that stops the audio and goes back to the beginning of the track currently being played. I thought about using the current playback postion somehow, but can't get my head around that.
我也试过这个(在另一个问题中修改的建议) ,无效:
I've also tried this (adapted by advice here in another question), to no avail:
` function stop() {
var audioPlayer = document.getElementsByTagName('audio');
addEventListener('loadedmetadata', function() {
this.currentTime = 0;
}, false);
}
`
任何想法?
推荐答案
如果您的播放/暂停正常工作,则应该停止:
If your play/pause is working, this should work for stop:
function stop() {
var audioPlayer = document.getElementsByTagName('audio')[0];
audioPlayer.pause();
audioPlayer.currentTime = 0;
}
这篇关于HTML5音频控制停止按钮(而不是暂停)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!