开发者

How can i get HTML5 audio playlist with mediaelement.js ?

I tried 开发者_如何学Cto 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.

HTML:

<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&amp;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&amp;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&amp;file=linkto/music.mp3" />
        </object>
    </audio>
</figure>
<!-- .entry-audio -->

JavaScript:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜