0
Good morning!
I have a question regarding to be working with audio in a Web application, I have an App made in Python using Flask that sweeps a certain directory that has several MP3, so I create dynamically the DIV containing the Audio Players and they have the same ID.
Follow the Example:
library_music audio1.mp3 Your browser does not support the audio tag.library_music audio2.mp3 Your browser does not support the audio tag.
library_music audio3.mp3 Your browser does not support the audio tag.
The application works perfectly, but I need to play a single song at a time, so I believe the way is to use Javascript but I do not know how to proceed in this case that TAGS are created dynamically with the same ID.
If anyone can lend a hand I’d appreciate it!
"I dynamically create the DIV containing the Audio Players and they have the same ID" This is already wrong, the ID should be single should not create more than one element with the same ID when creating or changing the ID or do not assign an ID.
– Ricardo Pontual
on the subject, the
audio
has an "ended" event that is triggered when you finish playing the audio, you can use that event to play the next audio– Ricardo Pontual
Right about the ID, quiet... I can stop using the same ID for each of them, only in case I want to prevent the user to play Players simultaneously, when the music finishes beauty, I don’t even need to start the other. I wanted a way to work with these rules if I can help I appreciate...
– Michael Mattos
the simplest would be to have a single audio element, but in your case you can handle the "play" event and cancel if another audio is already playing
– Ricardo Pontual
More ai in case I access which property of the tag Audio in Html ?
– Michael Mattos