简体   繁体   English

一页中的flowplayer多搜索按钮

[英]flowplayer multi seek buttons in one page

I have 2 videos in one page and each video have seek buttons but when I click on seek buttons on the first video the second video also effective. 我在一页中有2个视频,每个视频都有搜索按钮,但是当我单击第一个视频上的搜索按钮时,第二个视频也有效。 but when I click on the seek buttons in the second video it's working fine, so I want each self-contained independent video 但是当我单击第二个视频中的“搜索”按钮时,它运行良好,所以我希望每个独立的独立视频

flowplayer(function(api, root) {

$(".rewind").click(function (rebtn) {
  if (api.playing) {
    //var target = $(this).attr("id") == "forward" ? 3 : -3;

     var target = document.getElementById(jQuery(rebtn).closest('div.video-container').find('video.myvideo').attr('id'))  == "forward" ? -3 : -3;

    api.seek(api.video.time + target);
  }  
});

$(".forward").click(function (fwtn) {
  if (api.playing) {
    //var target = $(this).attr("id") == "forward" ? 3 : -3;
         var target = document.getElementById(jQuery(fwtn).closest('div.video-container').find('video.myvideo').attr('id'))  == "forward" ? 3 : 3;

    api.seek(api.video.time + target);
  }  
});

});








<div class="video-container">
            <div class="flowplayer player">
                  <video class="myvideo" id="myvideo">
                <source type="video/mp4" src="flow/1.mp4"/>
              </video>
                <div class="buttons">
                <a href="#" class="forward">forward</a>
                <a href="#" class="rewind">rewind</a>
                </div>
                  <div class="endscreen"> <a class="fp-toggle">Play it Again</a> </div>
                </div>

          </div>



<div class="video-container">
            <div class="flowplayer player">
                  <video class="myvideo" id="myvideo1">
                <source type="video/mp4" src="flow/1.mp4"/>
              </video>
                <div class="buttons">
                <a href="#" class="forward">forward</a>
                <a href="#" class="rewind">rewind</a>
                </div>
                  <div class="endscreen"> <a class="fp-toggle">Play it Again</a> </div>
                </div>

          </div>

Your flowerplayer function is running twice, once for each video; 您的flowerplayer功能正在运行两次,每个视频一次。 therefore, you are binding the click handler to all buttons with class .rewind/.forward twice. 因此,您将单击处理程序绑定到类为.rewind / .forward的所有按钮两次。

You could make your binding more specific like this: 您可以这样使绑定更具体:

$(root).on("click", ".rewind", function (rebtn) {...

In this way, each time the function is run, it will only add a handler to the rewind/forward buttons that apply to this player. 这样,每次运行该功能时,它只会将处理程序添加到适用于此播放器的快退/前进按钮。

You could also probably simplify to one handler: 您可能还可以简化为一个处理程序:

flowplayer(function (api, root) {
    $(root).on("click", ".rewind, .forward",function (rebtn) {
        if (api.playing) {
            var target = $(this).hasClass("forward") ? 3 : -3;
            api.seek(api.video.time + target);
        }
    });
});

Working DEMO 工作演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM