使用HTML5视频同步内容

时间:2017-08-05 17:29:06

标签: javascript jquery html5 video

我希望添加号召性用语按钮,这些按钮仅在播放视频时在特定时间参数期间出现。我目前正在使用javascript,它工作正常但是当我为视频添加超过1时,只有一个有效。

<!-- DO MORE-->
  <pre>
    <div hidden data-starttime=16 data-endtime=35 id="GrowDoMore"><button type="button" class="GrowDoGuide" data-toggle="modal" data-target="#GrowDoModal" id="growDo">Grow: Do More</button></div>
  </pre><!-- Modal -->
    <div class="modal fade" id="GrowDoModal" tabindex="-1" role="dialog" aria-labelledby="Grow: Do More">
      <div class="modal-dialog" role="document">
        <!-- <div class="modal-content">-->
        <a href="http://www.nascireland.org/" target="blank"><img src="imgs/doMore.png" width ="300%" class="center" /></a><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
        <div class="closeButton2"><button type="button" id="growDoClose" class="GrowDoGuide btn growDo" data-dismiss="modal" >Back to Documentary X</button></div>
      </div><!--</modal>-->
    </div><!--</modal>-->
    <!-- END DO MORE-->

var growVideo=document.getElementById("videogrow");
var makeVideo=document.getElementById("videomake");
var videoList=['mikethefrog.mp4','mikethefrog.mp4'];
var index = videoList.indexOf(window.currentVideoName);
var growLearnButton = document.getElementById("growLearn");
var growLearnCloseButton = document.getElementById("growLearnClose");
var growDoButton = document.getElementById("growDo");
var growDoCloseButton = document.getElementById("growDoClose");
var makeLearnButton = document.getElementById("makeLearn");
var makeLearnCloseButton = document.getElementById("makeLearnClose");
var makeDoButton = document.getElementById("makeDo");
var makeDoCloseButton = document.getElementById("makeDoClose");


//Next button
function nextButton(){
growVideo.pause();
growVideo.currentTime=0;
index = index + 1;
if(index==videoList.length)
index = 0;
alert(videoList[index]);
growVideo.src = 'videos/'+videoList[index];
window.currentVideoName=videoList[index];
growVideo.play();
}
function playPause()
{
if (growVideo.paused)
  growVideo.play();
else
  growVideo.pause();
}


//DOC2
//Next button
function nextButton(){
makeVideo.pause();
makeVideo.currentTime=0;
index = index + 1;
if(index==videoList.length)
index = 0;
alert(videoList[index]);
makeVideo.src = 'videos/'+videoList[index];
window.currentVideoName=videoList[index];
makeVideo.play();
}
function playPause2()
{
if (makeVideo.paused)
  makeVideo.play();
else
  makeVideo.pause();
}

//GrowLearnMoreGuide


  // Event listener for the guide buttons
  growLearnButton.addEventListener("click", function() {
    if (growVideo.paused == true) {
      // Play the video
      growVideo.play();

      // Update the button text to 'Pause'
      growLearnButton.innerHTML = 'Grow: Learn More';
    } else {
      // Pause the video
      growVideo.pause();

      // Update the button text to 'Play'
      growLearnButton.innerHTML = 'Grow: Learn More';
    }
  });

  // Event listener for the close buttons
  growLearnCloseButton.addEventListener("click", function() {
    if (growVideo.paused == true) {
      // Play the video
      growVideo.play();

      // Update the button text to 'Pause'
      growLearnCloseButton.innerHTML = 'X Back to Grow';
    } else {
      // Pause the video
      growVideo.pause();

      // Update the button text to 'Play'
      growLearnCloseButton.innerHTML = 'X Back to Grow';
    }
  });

  var GrowLearnMore = document.getElementById('GrowLearnMore');
  var GrowLearnMorestart = GrowLearnMore.getAttribute('data-starttime');
  var GrowLearnMoreend = GrowLearnMore.getAttribute('data-endtime');
  growVideo.ontimeupdate = function(e)
    {
      var hasHidden = GrowLearnMore.hasAttribute('hidden');
      if (growVideo.currentTime > GrowLearnMorestart && growVideo.currentTime < GrowLearnMoreend)
        {
          if (hasHidden) GrowLearnMore.removeAttribute('hidden');
        }
        else
          {
            if (!hasHidden) GrowLearnMore.setAttribute('hidden', '');
          }
        }

        //GrowDoMoreGuide



        // Event listener for the guide buttons
          growDoButton.addEventListener("click", function() {
            if (growVideo.paused == true) {
              // Play the video
              growVideo.play();

              // Update the button text to 'Pause'
              growDoButton.innerHTML = 'Grow: Do More';
            } else {
              // Pause the video
              growVideo.pause();

              // Update the button text to 'Play'
              growDoButton.innerHTML = 'Grow: Do More';
            }
          });

          // Event listener for the close buttons
          growDoCloseButton.addEventListener("click", function() {
            if (growVideo.paused == true) {
              // Play the video
              growVideo.play();

              // Update the button text to 'Pause'
              growDoCloseButton.innerHTML = 'X Back to Part 1: Grow';
            } else {
              // Pause the video
              growVideo.pause();

              // Update the button text to 'Play'
              growDoCloseButton.innerHTML = 'X Back to Part 1: Grow';
            }
          });

          var GrowDoMore = document.getElementById('GrowDoMore');
          var GrowDoMorestart = GrowDoMore.getAttribute('data-starttime');
          var GrowDoMoreend = GrowDoMore.getAttribute('data-endtime');
          growVideo.ontimeupdate = function(e)
            {
              var hasHidden = GrowDoMore.hasAttribute('hidden');
              if (growVideo.currentTime > GrowDoMorestart && growVideo.currentTime < GrowDoMoreend)
                {
                  if (hasHidden) GrowDoMore.removeAttribute('hidden');
                }
                else
                  {
                    if (!hasHidden) GrowDoMore.setAttribute('hidden', '');
                  }
                }
 //Guide2

// Event listener for the guide buttons
  makeLearnButton.addEventListener("click", function() {
    if (makeVideo.paused == true) {
      // Play the video
      makeVideo.play();

      // Update the button text to 'Pause'
      makeLearnButton.innerHTML = 'Grow Food';
    } else {
      // Pause the video
      makeVideo.pause();

      // Update the button text to 'Play'
      makeLearnButton.innerHTML = 'Grow Food';
    }
  });

  // Event listener for the close buttons
  makeLearnCloseButton.addEventListener("click", function() {
    if (makeVideo.paused == true) {
      // Play the video
      makeVideo.play();

      // Update the button text to 'Pause'
      makeLearnCloseButton.innerHTML = 'X Back to Make';
    } else {
      // Pause the video
      makeVideo.pause();

      // Update the button text to 'Play'
      makeLearnCloseButton.innerHTML = 'X Back to Make';
    }
  });

  var MakeLearnMore = document.getElementById('MakeLearnMore1');
  var MakeLearnMorestart = MakeLearnMore1.getAttribute('data-starttime');
  var MakeLearnMoreend = MakeLearnMore1.getAttribute('data-endtime');
  makeVideo.ontimeupdate = function(e)
    {
      var hasHidden = MakeLearnMore.hasAttribute('hidden');
      if (makeVideo.currentTime > MakeLearnMorestart && makeVideo.currentTime < MakeLearnMoreend)
        {
          if (hasHidden) MakeLearnMore.removeAttribute('hidden');
        }
        else
          {
            if (!hasHidden) MakeLearnMore.setAttribute('hidden', '');
          }
        }
.GrowLearnGuide
{
  width: 300px;
  position: relative;
  bottom: 190px;
  float:right;
  background-color: #ffc000;
  border-style: solid;
  z-index: 21474836;
}

.MakeLearnGuide
{
  width: 300px;
  position: relative;
  bottom: 190px;
  float:right;
  background-color: #ffc000;
  border-style: solid;
  z-index: 21474836;
}

  .GrowDoGuide
{
  width: 300px;
  position: relative;
  bottom: 190px;
  float:right;
  background-color: #ffcccc;
  border-style: solid;
  z-index: 21474837;
}

pre
{
  background-color: #2C2C2C;
  border: none;
  z-index: 2147483646;
}

.closeButton1
{
  font-family: 'Quicksand', sans-serif;
  font-size: 26pt;
  color: #000000;
  border: none;
  z-index: 2147483644;
  margin-left:820px;
  margin-top:-528px;
}

.closeButton2
{
  font-family: 'Quicksand', sans-serif;
  font-size: 26pt;
  color: #000000;
  border: none;
  z-index: 2147483644;
  margin-left:820px;
  margin-top:-528px;
}


button {
  background: rgba(0,0,0,.5);
  border: 0;
  color: #fff;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  -o-border-radius: 3px;
  border-radius: 3px;
  width: 60px;
  height: 60px;
}


button:hover {
  cursor: pointer;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<body>

<!--VIDEO 2 PART 2 -->
<div style="text-align:center">

    <h1>Part One: Grow</h1>

  <button onclick="playPause()">Play/Pause</button>
  <button onclick="nextButton()">Next</button>
  <br>
  <video id="videogrow" width="60%">
    <source src="http://fareireland.ie/mikethefrog.mp4" type="video/mp4">
    <source  type="video/mp3">
     <source type="video/ogg">
    Your browser does not support HTML5 video.
  </video>

  <!-- LEARN MORE-->
  <pre>
    <div hidden data-starttime=1 data-endtime=15 id="GrowLearnMore"><button type="button" class="GrowLearnGuide" data-toggle="modal" data-target="#GrowLearnModal" id="growLearn">Grow: Learn More</button></div>
  </pre><!-- Modal -->
    <div class="modal fade" id="GrowLearnModal" tabindex="-1" role="dialog" aria-labelledby="Grow: Learn More">
      <div class="modal-dialog" role="document">
        <!-- <div class="modal-content">-->
        <a href="http://www.nascireland.org/" target="blank"><img src="imgs/doMore.png" width ="250%" class="center" /></a><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
        <div class="closeButton1"><button type="button" class="GrowLearnGuide btn growLearn" data-dismiss="modal" id="growLearnClose">Back to Documentary X</button></div>
      </div><!--</modal>-->
    </div><!--</modal>-->
  <!-- END LEARN MORE-->
<!-- DO MORE-->
  <pre>
    <div hidden data-starttime=16 data-endtime=35 id="GrowDoMore"><button type="button" class="GrowDoGuide" data-toggle="modal" data-target="#GrowDoModal" id="growDo">Grow: Do More</button></div>
  </pre><!-- Modal -->
    <div class="modal fade" id="GrowDoModal" tabindex="-1" role="dialog" aria-labelledby="Grow: Do More">
      <div class="modal-dialog" role="document">
        <!-- <div class="modal-content">-->
        <a href="http://www.nascireland.org/" target="blank"><img src="imgs/doMore.png" width ="300%" class="center" /></a><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
        <div class="closeButton2"><button type="button" id="growDoClose" class="GrowDoGuide btn growDo" data-dismiss="modal" >Back to Documentary X</button></div>
      </div><!--</modal>-->
    </div><!--</modal>-->
    <!-- END DO MORE-->


  </div>
<!--END OF VIDEO 1 PART 1 -->



<!--VIDEO 2 PART 2 -->
<div style="text-align:center">
  <h1>Part Two: Make</h1>
  <button onclick="playPause2()">Play/Pause</button>
  <button onclick="nextButton2()">Next</button>
<br>
    <video id="videomake" width="60%">
    <source src="http://fareireland.ie/mikethefrog.mp4" type="video/mp4">
    <source  type="video/mp3">
     <source type="video/ogg">
    Your browser does not support HTML5 video.
  </video>

  <pre>
    <div hidden data-starttime=2 data-endtime=25 id="MakeLearnMore1"><button type="button" class="MakeLearnGuide" data-toggle="modal" data-target="#MakeDoModal" id="makeLearn">GROW FOOD</button></div>

  </pre><!-- Modal -->
    <div class="modal fade" id="MakeLearnModal" tabindex="-1" role="dialog" aria-labelledby="Make: Learn More">
      <div class="modal-dialog" role="document">
        <!-- <div class="modal-content">-->
        <a href="http://www.nascireland.org/" target="blank"><img src="imgs/doMore.png" width ="300%" class="center" /></a><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
        <div class="closeButton1"><button type="button" class="MakeLearnGuide btn makeLearn" data-dismiss="modal" id="makeLearnClose">testc Back to Documentary X</button></div>
      </div><!--</modal>-->
    </div><!--</modal>-->

</div>
<!--END OF VIDEO 2 PART 2 -->
<script src="video.js"></script>
<script src="growlearn.js"></script>
<script src="growDo.js"></script>
<script src="makelearn.js"></script>
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="bootstrap.min.js"></script>
</body>
</html>

它在某种程度上起作用,但是当一个视频添加了多个时,一个将无法正常工作。

以下是关于jsfiddle的代码:https://jsfiddle.net/ktdonohoe/cnma4s6b/

视频在那里不起作用,但基本上按钮应该出现在每个视频的某个时间范围内,如下所示: enter image description here

我根据2011年发现的一篇文章https://www.smashingmagazine.com/2011/03/syncing-content-with-html5-video/

来做这件事

我想知道是否有更新的方法来执行此操作,或者是否有人知道解决此问题的方法。

0 个答案:

没有答案