Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML audio Element how to replay?

I setup a HTML5 page, that include a node. The page will to playing a music(mp3 format),but it just play sound to end, and I use javascript to control audio element,even so,I can't replay it and only STOP.

Does HTML5 audio Element support REPLAY? And how to?

like image 218
Dreampuf Avatar asked Aug 10 '11 03:08

Dreampuf


2 Answers

please read this

http://www.position-absolute.com/articles/introduction-to-the-html5-audio-tag-javascript-manipulation/

and for replay event

you can set option, on replay click

audioElement.currentTime=0;
audioElement.play();
like image 56
Pramendra Gupta Avatar answered Nov 03 '22 10:11

Pramendra Gupta


The suggestions above did not worked for me or where not applicable. I needed to replay sound when my code needed to do it.

The following code worked (at least chrome):

audioElement.setAttribute('src', audioSrc); audioElement.play();

in other words, setting the src attribute again, then play() did the job

like image 38
Fred Peters Avatar answered Nov 03 '22 08:11

Fred Peters