<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#play-bt").click(function(){
$(".audio-player")[0].play();
$(".message").text("Music started");
})
$("#pause-bt").click(function(){
$("#audio-player")[0].pause();
$(".message").text("Music paused");
})
$("#stop-bt").click(function(){
$(".audio-player")[0].pause();
$(".audio-player")[0].currentTime = 0;
$(".message").text("Music Stopped");
})
})
</script>
</head>
<body>
<audio class ="audio-player" name="" src="01-Breakin-A-Sweat-Zedd-Remix.mp3" ></audio>
<audio class ="audio-player" name="" src="04-zedd-stars_come_out_(terravita_remix)" ></audio>
<div class ="message"></div>
<a id = "play-bt" href="#">Play music</a> | <a id ="pause-bt" href="#">Pause music</a> | <a id ="stop-bt" href="#">Stop music</a>
</body>
</html>
This code only plays the first audio tag, how will I be able to play the next song/track/audio tag?
All the audio elements loaded are in an array, which you can access using the methods you have. If you add a next track function you can browse through all the elements, like so:
It finds the amount of audio elements with jquery .length, and when you reach the last track it starts from the first one. Here’s an example -> http://jsfiddle.net/8GycB/46/