Introduction
In this article, we will discuss how to create a simple audio player using HTML5, CSS, and jQuery. Here we use an HTML5 <audio> tag, jQuery Scroller, and many CSS styles to make the Audio Player like this

First, we take the following Image (MYPLayer.png) and set it in the background like this:
Step 2
- <div style="background-image:url(MYPLayer.png);height:210px;width:335px;">
- </div>
After that we will take an <audio> tag of HTML5 like this:
<audio id="player" ></audio>
Step 3
After that, we will take the images for our Play, Pause, Stop, Previous and Next Button.
Step 4
Now we will write the code for Play Button:
- <img id="imgplay" onclick="PlayMusic()" onmouseout="this.style.opacity=1" onmouseover="this.style.opacity=0.7" src="Image\MainPlay Button.png" />
Here we set the opacity of the image and set the source of the image. The output will be:
- function PlayMusic()
- {
- document.getElementById('imgplay').src="Image/ClickPlayButton.png";
- document.getElementById('player').play();
- }
And we define the play() to play the selected audio file.
Step 5
Now we will be writing the code for the Pause Button.
For that we first take the following image:
- <img id="stopmusic" onclick="StopMusic()" src="Image\Stop Button.png" onmouseout="this.style.opacity=1" onmouseover="this.style.opacity=0.7" />
- function PauseMusic()
- {
- document.getElementById('pausemusic').src="Image/ClickPauseButton.png";
- document.getElementById('player').pause();
- }
Now we write the code for the Stop Button:
Now we will write the JavaScript code:
Step 7
- <img id="stopmusic" onclick="StopMusic()" src="Image\Stop Button.png" onmouseout="this.style.opacity=1" onmouseover="this.style.opacity=0.7" />
- function StopMusic()
- {
- document.getElementById('stopmusic').src="Image/ClickStopButton.png";
- document.getElementById('player').src="";
- document.getElementById('ploop').style.display='none';
- }
Now we will be writing the code for the Previous Music Button:
Now we will write the JavaScript code:
Step 8
- <img id="playpreviousmusic" src="Image\Previous Button.png" onmouseout="this.style.opacity=1" onmouseover="this.style.opacity=0.7" onclick="PlayPreviousMusic()" />
- function PlayPreviousMusic1()
- {
- document.getElementById('playpreviousmusic').src="Image/Previous Button.png";
- }
Now we will write the code for the Next Music Button:
Now we will write the JavaScript code:
Step 9
- <img id="playnextmusic" src="Image\NextButton.png" onmouseout="this.style.opacity=1" onmouseover="this.style.opacity=0.7" onclick="PlayNextMusic()" />
- function PlayNextMusic()
- {
- document.getElementById('playnextmusic').src="Image/ClickNextButton.png";
- }
Now we will write the code for the loop, it will run automatically. When the song is finished it will stop. For this use the following procedure:
Step 10
- <p id="ploop" style="color:#3F6B7B;font-size:small;"></p>
- public partial class _Default : System.Web.UI.Page
- {
- function Loop()
- {
- var duration = document.getElementById('ploop');
- var s = parseInt(document.getElementById('player').currentTime);
- var x= parseInt(document.getElementById('player').currentTime)/s;
- var m = parseInt((document.getElementById('player').currentTime));
- duration.innerHTML = '0' + m;
- if(document.getElementById('player').ended)
- {
- document.getElementById('ploop').innerHTML="";
- }
- else
- {
- setTimeout("Loop()",200);
- }
Now we will look at the Volume Control.
Here we take a jQuery Data Slider like this:
- <input type="text" id="Text1" value="0.2" data-slider="true" style="margin:0 0 0px 0px;color:White;" onmouseout="this.style.opacity=1" onmouseover="this.style.opacity=0.7"/></p>
- <script>
- $(function () {
- $("#slider").slider({
- value: 100,
- min: 0,
- max: 500,
- step: 50,
- slide: function (event, ui) {
- $("#amount").val("$" + ui.value);
- }
- });
- $("#amount").val("$" + $("#slider").slider("value"));
- });
- </script>
Here we specify the CSS of that control; we will also include the JavaScript files, so the output will be





vinay kashyapPosted Sep 21, 2014, 6:29 AM
Good Coding
Sourabh SomaniPosted Sep 20, 2014, 3:48 AM
nice :)
Abhishek JaiswalPosted Sep 20, 2014, 12:03 AM
I guess HTML5 only supports MP4, OGG, WEBM.
Vithal WadjePosted Sep 19, 2014, 3:31 PM
great one,can i play .MOV video files ?
Abhishek JaiswalPosted Sep 19, 2014, 10:59 AM
Pretty cool!
Mahak GuptaPosted Aug 25, 2013, 3:00 PM
Thanks
Mostafa EyniPosted Aug 25, 2013, 2:54 PM
very very very thank you ,best regards.