当当前的HTML5结尾时,如何播放下一个音轨?

时间:2018-09-29 22:02:46

标签: javascript html5 css3 ecmascript-6 ecmascript-2017

下面的代码应该播放单个MP3文件,其想法是跳到曲目的特定部分,然后从那里开始播放。尽管光标移动到了mp3中的正确位置,但是从按钮上单击“开始”后它不会播放。

<!DOCTYPE html>
        <html>
        <head>
        <title>Song Limit</title>
        </head>
        <body>
        <div style="margin: 20px; text-align: center;">
        <audio id="myVideo" controls>
        <source src="gpj.mp3" type="video/mp4">
        <source src="gpj.mp3" type="video/ogg">
        Your browser does not support HTML5 video.
        </audio>
        <p>
        <b> The Auido Run From Start </b></br>
        <a onclick="setCurTime(0)" href="javascript:void(0)">Start from 0 sec</a>
        </p>
        <br>
        <p>
        <b> The Auido Run From Start </b></br>
        <a onclick="setCurTime(20)" href="javascript:void(0)">Start from 20 sec</a>
        </p>
        <br>
        <p>
        <b> The Auido Run From Start </b></br>
        <a onclick="setCurTime(35)" href="javascript:void(0)">Start from 35 sec</a>
        </p>
        <br>
        <p>
        <b> The Auido Run From Start </b></br>
        <a onclick="setCurTime(47)" href="javascript:void(0)">Start from 47 sec</a>
        </p>
        </div>
        <script>
        var vid = document.getElementById("myVideo");
        function setCurTime(time_start) {
        vid.currentTime = time_start;
        }
        </script>


        </body>
</HTML>
        </html>

2 个答案:

答案 0 :(得分:0)

此后,您需要致电vid.play()。如下

function setCurTime(time_start) {
    vid.currentTime = time_start;
    vid.play();
  }

P.S请记住为您的文件而不是video / mp4设置正确的类型

答案 1 :(得分:0)

也许这将解决您的问题。

 <script>
    var vid = document.getElementById("myVideo");
      function setCurTime(time_start) {
      vid.currentTime = time_start;
      vid.play()
    }