Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在播放下一首音频曲目时停止此特定音频播放器(HTML5+;JavaScript)_Javascript_Html_Html5 Audio - Fatal编程技术网

如何在播放下一首音频曲目时停止此特定音频播放器(HTML5+;JavaScript)

如何在播放下一首音频曲目时停止此特定音频播放器(HTML5+;JavaScript),javascript,html,html5-audio,Javascript,Html,Html5 Audio,我的页面上有多个音频播放器,我正在使用。它们都工作得很好,但是如果你点击第二个播放器,第一个就会继续播放。我以前见过这个问题,但是没有一个答案是针对这个音频播放器的。如果我得到了正确的播放器代码,那么您可以使用jQuery暂停/停止所有播放器 $('.audioplayer-playpause').bind('click', function () { $('.audioplayer-playing').stop() #that will stop all the audioplayers

我的页面上有多个音频播放器,我正在使用。它们都工作得很好,但是如果你点击第二个播放器,第一个就会继续播放。我以前见过这个问题,但是没有一个答案是针对这个音频播放器的。

如果我得到了正确的播放器代码,那么您可以使用jQuery暂停/停止所有播放器

$('.audioplayer-playpause').bind('click', function () {
  $('.audioplayer-playing').stop() #that will stop all the audioplayers which are currently playing audio
})

这是我的问题的解决方案,我以前在做什么:

<script>
$( function()
{
    $( 'audio' ).audioPlayer();
});
</script>

$(函数()
{
$('audio').audioPlayer();
});
我现在所做的,经过多个浏览器测试,它可以工作:

<script>
$( function()
{
    $( 'audio' ).audioPlayer();
    var $audios = $('audio').on('play', function(){
        $audios.not(this).parents('.audioplayer-playing').find('.audioplayer-playpause').trigger('click');
    });
});
</script>

$(函数()
{
$('audio').audioPlayer();
var$audios=$('audio')。在('play',function()上{
$audios.not(this).parents('.audioplayer playing')。find('.audioplayer playpaise')。trigger('click');
});
});

将.audioplayer添加到DOM后