0

感谢您的光临。我正在创建一个页面来循环播放视频剪辑。循环通过部分(run()函数)工作得很好。我还创建了一些按钮来播放特定的视频剪辑,但这些都不起作用。我只写了第一个按钮的功能,当我第一个工作时我会写另外两个。

如果非常感谢任何帮助。

谢谢,汤米

<video id="tutorials" autoplay onended="run()" 
    autobuffer="true" width="600px" height="350px" controls>
<source src="video1.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
</video>

<br>
<br>

<button id="tut1">Play Tutorial 1</button>
<button id="tut2">Play Tutorial 2</button>
<button id="tut3">Play Tutorial 3</button>

<script type="text/javascript">

    video_count =1;
    videoPlayer = document.getElementById("tutorials");

    function run()
    {
        video_count++;
        if (video_count == 4) return;
        var nextVideo = "video"+video_count+".mp4";
        videoPlayer.src = nextVideo;
        videoPlayer.play();
    };

    document.getElementByID("tut1").onclick = function()
    {
        videoPlayer.stop();
        videocount = 1;
        var video = "video1.mp4";
        videoPlayer.src = video;
        videoPlayer.play();
    }

</script>
4

1 回答 1

0

我更喜欢以这种方式构造代码:

<script type="text/javascript">

  video_count =1;
  videoPlayer = document.getElementById("tutorials");

  function runNext()
  {
    runVideo(video_count+1);
  }

  function runVideo(number)
  {
    if (number > 3) return;
    video_count = number;
    videoPlayer.src = "video"+video_count+".mp4";
    videoPlayer.play();
  }

</script>

HTML:

<button id="tut1" onclick="runVideo(1);">Play Tutorial 1</button>
<button id="tut2" onclick="runVideo(2);">Play Tutorial 2</button>
<button id="tut3" onclick="runVideo(3);">Play Tutorial 3</button>
于 2013-10-20T16:12:04.573 回答