Re: [問題] 請問一下如何設定audio的終點
※ 引述《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)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章
11
21