Plain HTML5 audio player : duration and start

时间:2015-10-06 08:50:37

标签: javascript html html5 audio

It's very simple to design an audio player with HTML5 :

 <audio controls>
  <source src="http://picosong.com/cdn/27590d7ce366627ec0d20d06ec2bbe1c.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio> 

I would like to set a starting point (ex: 1'26") and a duration (ex: 10 seconds), i.e. the player shouldn't display the whole audio file, but only these 10 seconds.

How to do set start point and duration with HTML5's <audio> with plain HTML5 or HTML5+JS? (i.e. no big third party JS library)

1 个答案:

答案 0 :(得分:1)

You can set the playback range in audio files url. Like this #t=[starttime][,endtime]

mdn article

Example:

<audio controls>
  <source src="http://picosong.com/cdn/27590d7ce366627ec0d20d06ec2bbe1c.mp3#t=120,130" type="audio/mpeg">
Your browser does not support the audio element.
</audio>