-1

I am a beginner in html. I made my website and it contains various audio elements. I want that only one audio element should be played at a time I got jquery code from another question. But when I play first song for 10s and then move on to next one and when I again play the first song then it starts from 10s. I want that it should start from the begining. Can anyone help me. Give me the jquery code Thanx in advance

1 Answers1

0

There is no .stop() function for audio elements. We can only pause them. And when we want to start from the beginning of the audio file we change its .currentTime. We will use this line in our example audioElement.currentTime = 0;. To achieve .stop() function we first pause the file then reset its time.

We may want to know the length of the audio file and the current playing time. We already learnt .currentTimeabove, to learn its length we use .duration.

use the following snippet to set the timing of the audio file from starting.

 $('#restart').click(function() {
        audioElement.currentTime = 0;
 });

Source: Play an audio file using jQuery when a button is clicked

Ramakanth Putta
  • 676
  • 4
  • 15