I tried to search the example of audio playlist in mediaelement.js. But i found none, is mediaelement.js supports audio playlist? If so, please kindly support me the sample code or links. Thank you very much.
I managed to get a super basic (read: hacky) demo of a playlist working in a WordPress theme I’ve got going. All you have to do is setup multiple media elements using a set of IDs, a class or in this case the <audio>
tag.
Then you can use JS to see when a player has ended (stopped playing music) and run some basic conditionals to see which player is playing, what player should play next and if there is no next player, start over from the beginning. Again this is very hacky, but it seems to be working for me.
<figure class="entry-audio">
<audio id="wp_mep_1" controls="controls">
<source src="linkto/music.mp3" type="audio/mp3" />
<object width="100%" height="23" type="application/x-shockwave-flash" data="flashmediaelement.swf">
<param name="movie" value="flashmediaelement.swf" />
<param name="flashvars" value="controls=true&file=linkto/music.mp3" />
</object>
</audio>
</figure>
<!-- .entry-audio -->
<figure class="entry-audio">
<audio id="wp_mep_2" controls="controls">
<source src="linkto/music.mp3" type="audio/mp3" />
<object width="100%" height="23" type="application/x-shockwave-flash" data="flashmediaelement.swf">
<param name="movie" value="flashmediaelement.swf" />
<param name="flashvars" value="controls=true&file=linkto/music.mp3" />
</object>
</audio>
</figure>
<!-- .entry-audio -->
<figure class="entry-audio">
<audio id="wp_mep_3" controls="controls">
<source src="linkto/music.mp3" type="audio/mp3" />
<object width="100%" height="23" type="application/x-shockwave-flash" data="flashmediaelement.swf">
<param name="movie" value="flashmediaelement.swf" />
<param name="flashvars" value="controls=true&file=linkto/music.mp3" />
</object>
</audio>
</figure>
<!-- .entry-audio -->
jQuery(function (jQuery) {
// make an array for the mediaelement players
var mediaElementPlayers = new Array();
// run mediaelement.js (Ignore options)
jQuery('audio').mediaelementplayer({
iPadUseNativeControls: false,
iPhoneUseNativeControls: false,
AndroidUseNativeControls: false,
pauseOtherPlayers: true,
success: function (mediaElement, domObject) {
// add this mediaelement to the mediaElementPlayers array
mediaElementPlayers.push(mediaElement);
console.log(mediaElement);
mediaElement.addEventListener('ended', function (e) {
playNext(e.target);
}, false);
},
keyActions: []
})
// find the current player and start playing the following player
function playNext(currentPlayer) {
for (i = 0; i < mediaElementPlayers.length; i++) {
if (mediaElementPlayers[i] == currentPlayer) {
if (mediaElementPlayers[i + 1] == undefined) { // If this is the last player Start from the beginning
mediaElementPlayers[0].play();
} else { // Start the next player
mediaElementPlayers[i + 1].play();
}
}
}
}
});
Nope, no playlist. If you looking for player that has one, check here: http://praegnanz.de/html5video/ Also, you can easy make playlist simply by using mediaelementjs JavaScript API. It is pretty simple task, IMO there is no need for extra support for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With