Answer the question
In order to leave comments, you need to log in
How to properly save and use playlist for HTML5 Audio tag?
Hello, I'm designing a native player, without external plugins. I think how to solve such a problem. I get a set of IDs with Ajax, I need to save them somehow, then when I play a track or when I press the button, turn on the next track. And if the ID is over, get a new batch.
This raises two questions:
1) Where to store them? In markup?
2) How to understand that the ID is over? After the end of playback or pressing the Next button, delete the current ID ?
There is an idea how to implement this, but I want to do it correctly and without shitty code.
Any thoughts?)
Answer the question
In order to leave comments, you need to log in
1)
Sound in html5 can be played not only with an audio tag, but also with a js object.
For example,
<audio controls>
<source src="audio_file.mp3" type="audio/mpeg">
</audio>
<script>
var audio = new Audio('audio_file.mp3');
audio.play();
</script>
var my_music = new Array();
$.post('audio_server.php').done(function(data){
//data - это, допустим, json с сервера со списком музыки (в виде ссылок)
my_music = $.parseJSON(data);// вот здесь и хранится список песен
var audio = new Audio( my_music[0] ); // запускаем первый трек
audio.play();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question