0
    <script type="text/javascript">
function playVideo(sourceId, targetId) {
   if (typeof(sourceId)=='string') {sourceId=document.getElementById(sourceId);}
   if (typeof(targetId)=='string') {targetId=document.getElementById(targetId);}
   targetId.innerHTML=sourceId.innerHTML;
   return false;

   }
    </script>
<video id="6" width="320" height="240" controls="controls"></video>

<video id="1" style="display: none;"width="320" height="240" controls="controls">
  <source src="movie1.mp4" type="video/mp4" />
  <source src="movie1.ogg" type="video/ogg" /> 
  <source src="movie1.webm" type="video/webm" />
Your browser does not support the video tag.
</video>
<video id="2" style="display: none;" width="320" height="240" controls="controls">
  <source src="movie2.mp4" type="video/mp4" />
  <source src="movie2.ogg" type="video/ogg" /> 
  <source src="movie2.webm" type="video/webm" />
Your browser does not support the video tag.
</video>


<a href="#" onclick='return playVideo("1","6")'>Play Video 1</a>
<a href="#" onclick='return playVideo("2","6")'>Play Video 2</a>

当视频 1 正在播放视频 2 时选择“播放视频 2”将不起作用,我该如何解决这个问题?是否需要添加其他脚本才能使第二个视频覆盖第一个?

4

2 回答 2

0

The way your playVideo function works is...not intuitive.

Use videoElement.play(); to play a video. For example, document.getElementById('1').play();. To stop a video from playing, use stop();

Tutorial / docs

于 2012-07-17T13:08:13.193 回答
0
<script type="text/javascript">
    function playVideo(sourceId, targetId) {
        if (typeof(sourceId)=='string') {sourceId=document.getElementById(sourceId);}
        if (typeof(targetId)=='string') {targetId=document.getElementById(targetId);}
        targetId.innerHTML=sourceId.innerHTML;
        return false;
    }
</script>

<div id="6"></div>

<div id="1" style="display: none">
    <video width="320" height="240" controls="controls">
        <source src="movie1.mp4" type="video/mp4" />
        Your browser does not support the video tag.
    </video>
</div>

<div id="2" style="display: none">
    <video width="320" height="240" controls="controls">
        <source src="movie2.avi" type="video/avi" />
        Your browser does not support the video tag.
    </video>
</div>

<a href="#" onclick='return playVideo("1","6")'>Play Video 1</a>
<a href="#" onclick='return playVideo("2","6")'>Play Video 2</a>

我做了什么:我将两个视频元素放在了 invisibledivs中。那些divs有 ids (1 & 2) 并且那些divs(你的视频元素) 的内容被加载到divid 为 6 的第三个(可见) 中。

于 2012-07-17T13:12:24.023 回答