作者CSLabor (电脑工人)
看板Ajax
标题Re: [问题] 请问一下如何设定audio的终点
时间Mon Apr 11 20:25:39 2011
※ 引述《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)