Run two videos at the same time with JavaScript

故事扮演 提交于 2020-01-07 02:03:50

问题


I would like run two videos at the same time after click on a play button that was created with JavaScript : https://jsfiddle.net/Lrt7nqyn/

At the moment, just one of videos run.

 <div class="player">
    <div class="mediaplayer">
      <video id="video1">
        <source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4" />
      </video>
      <video id="video2">
        <source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4" />
      </video>
  </div>
  <table>
    <tr>
      <th>Time</th>
      <td>
          <input class="time-slider" type="range" disabled value="0" step="any" />
      </td>
    </tr>
    <tr>
      <td>
          <input value="Play" type="button" class="play" />
      </td>
    </tr>
    <tr>
      <td>
         <input value="Stop" type="button" class="pause" />
      </td>
    </tr>
    <tr>
      <th>Mute</th>
      <td>
        <input class="muted" type="checkbox" />
      </td>
    </tr>
    <tr>
      <th>Volume</th>
      <td>
        <input class="volume-slider" type="range" value="1" max="1" step="0.01" />
      </td>
    </tr>
  </table>
</div>

回答1:


try this:

JSfiddle: https://jsfiddle.net/1co0x58v/

$('input.play', player).bind('click',function () {
      $('video, audio', player)[0].play();
      $('video, audio', player)[1].play(); // add this line to play second video
});
$('input.pause', player).bind('click',function (){
      $('video, audio', player)[0].pause();
      $('video, audio', player)[1].pause(); // add this line to pause second video
});


来源:https://stackoverflow.com/questions/37158000/run-two-videos-at-the-same-time-with-javascript

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