Re: [問題] 請問一下如何設定audio的終點

看板Ajax作者 (電腦工人)時間14年前 (2011/04/11 20:25), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《Cayley (水色天藍)》之銘言: : 好像有兩種方式可以設定audio的起點 : 一種是設定他的attribute : audio.currentTime : 另一種是直接填到 audio.play( startTime ) 之中 : 不過我卻找不到方法可以設定播放的終點 : 有Google到疑似解答的網站 : http://www.w3.org/TR/html5/video.html#text-track-cue-start-time : 但照著作的時候作不太出來 : 想請問各位大大,要如何設定audio的播放終點呢?? : 底下是我寫的小程式 以下是我想到的步驟 1.在audio object註冊timeupdate事件 並且定義當事件發生時被觸發的function 2.在被觸發的function利用 audio.currentTime / audio.duration * 100 可以得知你的音樂播放的百分比 也就是你的音樂已經播放到百分之多少了 就把你的終點換算成百分比 只要播放百分比大於等於你的終點 就可以audio.pause()叫它暫停了 : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ : <header> : <audio src='http://www.theqi.com/buddhism/GL1/audio/024B.MP3' id="audio" : controls></audio> : <script> : var init = function(){ : var audio = document.getElementById("audio"); : audio.currentTime = 10 : } : </script> : <p> : <button type="button" onclick="audio.play();">Play</button> : <button type="button" onclick="audio.pause();">Pause</button> : <button type="button" onclick="audio.currentTime = 0;"><< : Rewind</button> : </p> : </header> : <body onload="init();"> : </body> : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.116.177.31 ※ 編輯: CSLabor 來自: 140.116.177.31 (04/11 20:26)
文章代碼(AID): #1DelD5S5 (Ajax)
文章代碼(AID): #1DelD5S5 (Ajax)