2015-04-12 33 views
-1

我在html中有一個音頻文件。 我想要4個按鈕:一個用於播放,一個用於暫停,一個用於停止,一個用於30秒跳過。 暫停/播放的作品。其他2不。我花了2個小時嘗試和通過互聯網搜索,我簡直不明白。 這是我的代碼。我想停止/跳過HTML中的音頻30秒

<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> 

回答

1

你沒有一個音頻變量。您需要抓取播放器並直接對播放器進行更改。您還需要在stopsong()上暫停(),否則它將返回到開頭但繼續播放。

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 **/ 

}