如何在页面中只有一个jwplayer的时间播放,而其他玩家停止播放


How to play at time only one jwplayer in page while other players stop which are playing

如何停止页面中的所有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>';
} ?>

在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不太好。希望这能对你有所帮助。