mediaelement.js - play another video at end of 1st video

拟墨画扇 提交于 2019-12-03 14:41:26

问题


Referred by Kroc @ Video for Everyone. I'd like to be able to automatically play a second video after first one ends, and then display a static image after the second one ends. After a set period of time, loop back to the first video.

Thanks


回答1:


$(function(){
        $('audio,video').mediaelementplayer({
            success: function(player, node) {
                player.addEventListener('ended', function(e){
                    player.src = 'media/somefile.mp4';
                    player.load();
                    player.play();
                });
            }
        });
    });

That should do it.




回答2:


to change src of video you have to use setSrc API method. otherwise is wouldn't work for flash in browsers which don't support html5 (e.g. Firefox)

one more important thing - look at this issue - Chrome / Safari, setSrc -> play. it should be some timeout to show video properly in Chrome.

Unfortunately "player" not always works, so it's better to user "media" object.

So the code should be something like the following:

       $('video').mediaelementplayer({
            pluginPath: "/YourPlaginPath/",
            success: function (media, node, player) {
                media.addEventListener('ended', function (e) {

                    setTimeout(function () {
                        media.setSrc('somevideo.mp4');
                        media.load();
                        media.play();
                    }, 500);

                }, false);
            }
        });


来源:https://stackoverflow.com/questions/6269969/mediaelement-js-play-another-video-at-end-of-1st-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!