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
Asked
Active
Viewed 38 times
-1
-
'Give me the jquery code' I'm sorry, but that's not how this site works. – Rory McCrossan Jul 04 '17 at 10:31
-
1Possible duplicate of [Play an audio file using jQuery when a button is clicked](https://stackoverflow.com/questions/8489710/play-an-audio-file-using-jquery-when-a-button-is-clicked) – Ramakanth Putta Jul 04 '17 at 10:31
-
@Rory McCrossan,I was about to type that. – Hema Nandagopal Jul 04 '17 at 10:31
-
1provide your code snippet and elaborate your question,. – kalpesh jetani Jul 04 '17 at 11:22
1 Answers
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