我想停止/跳过30秒的HTML音频 [英] I want to stop/skip 30 seconds on audio in HTML

查看:62
本文介绍了我想停止/跳过30秒的HTML音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html音频文件.我要在那里有4个按钮:一个用于播放,一个用于暂停,一个用于停止,一个跳过30秒.暂停/播放.其他2个没有.我花了2个小时尝试和搜索互联网,但我根本听不懂.这是我的代码.

I have an audio file in html. I want 4 buttons there: one for play,one for pause,one for stop,one for 30 seconds skip. Pause/Play works. The other 2 don't. I spent 2 hours trying and searching through internet and I simply can't understand. Here is my code.

<script>
function playsong() {
    document.getElementById("Player").play();
}

function pausesong() {
    document.getElementById("Player").pause();
}

function stopsong() {
    document.getElementById('Player').setcurrentTime();/**tried also with audio.currentTime here. Didn't worked **/
    audio.currentTime = 0;
}

function forwardAudio() {
    document.getElementById('Player').setcurrentTime(); /**tried also with audio.currentTime here. Didn't worked **/
    audio.currentTime += 30.0

}
</script>

<body>
    <img src="http://www.marphahiphop.tv/wp-content/uploads/2012/06/Lu-K-Beats.jpg" height="300" width="200">
    <video width="420" height="340" controls="controls">
        <source src="http://176.9.192.221/mp4/5/Lilly%20Wood%20&%20The%20Prick%20and%20Robin%20Schulz%20-%20Prayer%20In%20C%20(Robin%20Schulz%20Remix)%20(Official).mp4" type="video/mp4" />
        <object data="movie.mp4" width="420" height="340">
            240" />
        </object>
    </video>
    <audio controls="controls" autoplay ID="Player">
        <source src="http://afewbitsmore.com/albums/Macklemore%20and%20Ryan%20Lewis/The%20Heist%20[2012]/The%20Heist%20[2012]-02-Macklemore;%20Ray%20Dalton;%20Ryan%20Lewis%20-%20Can't%20Hold%20Us.mp3" />
    </audio>
    <button type="button" onclick="playsong()">Play</button>
    <button type="button" onclick="pausesong()">Pauza</button>
    <button type="button" onclick="stopsong()">Stop</button>
    <button type="button" onclick="forwardAudio()">Skip 30 seconds</button>
</body>

推荐答案

您没有音频变量.您需要抓住播放器,然后直接对播放器进行更改.您还需要在stopsong()上暂停(),否则它可以回到开始但继续播放.

You did not have an audio variable. You need to grab the player and make the changes directly to the player. You also need to pause() on stopsong() or it will go back to the beginning but continue to play.

function stopsong() {
    var player = document.getElementById('Player');
    player.pause();
    player.currentTime = 0;/**tried also with audio.currentTime here. Didn't worked **/
}

function forwardAudio() {
    var player = document.getElementById('Player');
    player.currentTime += 30.0; /**tried also with audio.currentTime here. Didn't worked **/

}

这篇关于我想停止/跳过30秒的HTML音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆