如何在页面上只播放一个jwplayer,而其他玩家停止播放

时间:2015-11-25 12:19:28

标签: php jquery jwplayer

如何阻止页面中的所有jwplayers。我的目标只是一次jwplayer游戏,容器ID是动态和独特的。

  

我想要这样。

$('All_dynamic_player_container_ids').stop();$('dynamic_player_container_id').play();

  

Jwplayer代码如下:

<?php while(list($display_name, $iId, $uid, $caption, $dt, $post_type, $ext,$blocked_user,$special,$stream_id, $comments, $likes, $userLiked , $exclusive) = mysql_fetch_array($result))
{ ?>
    <div class="post_image video_image<?php echo $iId ?>" id="video_image<?php echo $iId ?>"></div>
    <?php 
    echo '<script type="text/javascript">
    jwplayer("video_image'.$iId.'").setup({
    sources: [{
    file: "../vids/user/'.$uid.'-'.$iId.'.mp4", 
    },],
    image:"../imgs/user/'.$uid.'-'.$iId.'.jpg",
    logo: {
    file: "../images/logo/melogo.png",
    link: "http://'.SERVER.'",
    hide:true
    },
    modes: [{
    type: "html5"
    }],
    width: "100%",
    aspectratio: "16:9",
    autostart: false,
    });
    jwplayer("video_image'.$iId.'").onError ( function(event) {
    setTimeout(function()
    {
    jwplayer("player").play(true);
    },2000);
    }
    );
    </script>';

} ?>

1 个答案:

答案 0 :(得分:0)

在JavaScript中

你可以:

var myPlayers = $('.post_image div');
var numPlayers = myPlayers.length;
for (i=0;i<numPlayers;i++) {
    //this for loop will stop all the videos from playing
    jwplayer("'video_image'+i").stop();
}
//then you can play the video you want to play here

抱歉,我的php不是很好。希望这对你有帮助。