Custom controls using Java Script

If you want more control that these basic attributes (autoplay and loop), you can create custom controls using Java Script. audio and video have attributes, events and methods you can manipulate with Java-Script.
canplaytype(type)Whether the browser can play a particular type of media
currentTimeThe current playback position denoted in seconds
durationThe length of the audio file in seconds
play()Start playback at the current position
pause()Pause playback if the audio is actively playing
The following code allows the user to jump to specific time on a audio file.
    <source src="audio.ogg">
        <source src="audio.mp3">
<button title="Play at 30 seconds" onclick="playAt(30);">30 seconds</button>
    function playAt(seconds) {
        var audio = document.getElementsByTagName("audio")[0];
        audio.currentTime = seconds;;
There is no stop method. To stop use the pause method to to return to the beginning of the audio file via currentTime.
when creating your own custom controls, drop the controls Boolean attribute from audio.
Related Tutorial
Follow Us #