mediaelement.js Multiple videos on same page?

耗尽温柔 提交于 2019-12-07 06:40:05

问题


I'm trying to put multiple videos up on a page, however when I click on one to play, they all play? Has anyone else experienced this?

Heres a snippet of the code im using

$("video,audio").mediaelementplayer({
    success: function (player, node) {
        player.pause();
    }
});

$('.mag_video .overlay_exit, .mag_video .overlay_bg').live('click', function () {
    var _this = this;
    $("video,audio").each(function () {
        $(this)[0].player.pause();
    })
});

回答1:


There is an option available to disable this behavior which is named 'pauseOtherPlayers', setting it to false will allow you to play multiple videos at the same time.

I adapted your exemple code :

$("video,audio").mediaelementplayer({
    pauseOtherPlayers: false,
    success: function (player, node) {
      player.pause();
     }
});



回答2:


That's because your jQuery selector is selecting all videos on the page. You want something more specific like:

$('#video1').mediaelementplayer({
    success: function (player, node) {
        player.pause();
    }
});


$('#video2').mediaelementplayer({
    success: function (player, node) {
        player.pause();
    }
});


来源:https://stackoverflow.com/questions/8971874/mediaelement-js-multiple-videos-on-same-page

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