<script>
function audioStarted(audioSrc)
{ console.log(audioSrc)
var audios = audioSrc;
Object.keys(audios).forEach(function(player) {
player.addEventListener('play', function() { // We listen for the `play` event on each player
audios.forEach(function(player2) {
if (player !== player2) { // we find other players which don't match the one that started
player2.pause(); // we pause those other players
}
});
});
});
}
</script>
<audio src="<?= $call["FullFilePath"] ?>" id="player2" type="audio/mpeg"
onplay="audioStarted(this.currentSrc);" controls="controls"></audio>
强文本] 1 **
函数audioStarted(audioSrc) {console.log(audioSrc) var audios = audioSrc; Object.keys(audios).forEach(function(player){ player.addEventListener('play',function(){//我们在每个播放器上监听`play`事件 audios.forEach(function(player2){ if(player!== player2){//我们发现其他与开始的玩家不匹配的玩家 player2.pause(); //我们暂停其他玩家 } }); }); }); }