HTML5 audio with javascript

Create audioElement

var audioElement = document.createElement('audio');

want to use with current audio tag

var audioElement = document.getElementById('myaudio');

Play

audioElement.play();

Pause

audioElement.pause();

Stop

audioElement.pause();
audioElement.currentTime = 0;

Duration (show with seconds)

audioElement.duration

Current Time (seconds)

audioElement.currentTime

Go to 35 secons

audioElement.currentTime = 35;

Change music

audioElement.setAttribute('src', 'music/Track01.mp3'); audioElement.load();

Ogg for firefox and opera. Mp3 for safari and chrome.

comments powered byDisqus