简体   繁体   中英

MediaElement.js stops other players if another starts

I am using MediaElement.js and need other players to stop playing if another is starts.

This question has been asked before but I am a little confused as to how to apply this code.

I have seen others had solved this and had it working by using the following in jQuery:

$('video,audio').each(function() {
  $(this)[0].pause();
});

Where should I put this code? Or where exactly in the jquery.js file should I put it? I can't get it to work.

I need my other players to stop playing if another starts.

 /*new MediaElementPlayer('.player_1', {success: function(media, node, player) { // this will be undefined since it's the player with buttons alert(player.paused); // this will be a real value since it's the underlying mediaelement alert(media.paused); } });*/ $(document).ready(function() { $('audio').mediaelementplayer({ alwaysShowControls: true, features: ['playpause','volume','progress'], audioVolume: 'horizontal' //audioWidth: 400, //audioHeight: 120 }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://mediaelementjs.com/js/mejs-2.8.2/mediaelement-and-player.min.js"></script> <link href="http://mediaelementjs.com/js/mejs-2.8.2/mediaelementplayer.min.css" rel="stylesheet"/> <audio src="http://mediaelementjs.com/media/AirReview-Landmarks-02-ChasingCorporate.mp3" class="player_1"></audio> <audio src="http://www.jplayer.org/audio/mp3/TSP-01-Cro_magnon_man.mp3" class="player_2"></audio> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM