I cannot get Jplayer to play one song after the other when I use a button to play the first one.
When I hardcode the variable refid
eg. myPlaylist.select(3);
it works perfectly. But when I get the value from the html/php part it doesn't work, it plays the current song and then it stops.
Thank you in advance for your help.
And here is the php/html
echo'<td> <a href="" value="'.$songid.'" class="playitem1"> '. ucfirst($results['song_name']).' </td>';
And here is the javascipt :
$(document).ready(function(){
$(".playitem1").click(function(event){
event.preventDefault();
playthis($(this).attr("value"));
})
function playthis(refid){
myPlaylist.pause();
myPlaylist.select(refid);
myPlaylist.play();
}
var myPlaylist = new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
}, [{
title:"Cro Magnon Man",
artist:"The Stark Palace",
mp3:"http://www.jplayer.org/audio/mp3/TSP-01-Cro_magnon_man.mp3",
oga:"http://www.jplayer.org/audio/ogg/TSP-01-Cro_magnon_man.ogg",
poster: "http://www.jplayer.org/audio/poster/The_Stark_Palace_640x360.png"
},
{
title:"Your Face",
artist:"The Stark Palace",
mp3:"http://www.jplayer.org/audio/mp3/TSP-05-Your_face.mp3",
oga:"http://www.jplayer.org/audio/ogg/TSP-05-Your_face.ogg",
poster: "http://www.jplayer.org/audio/poster/The_Stark_Palace_640x360.png"
},
]);
});
For those who are interested I found the answer. The $songid
issued by the php is a string and not an integer, so I had to add parseInt();
to my javascript. The javascript looks like that now :
function playthis(refid){
refid = parseInt(refid);
myPlaylist.select(refid);
myPlaylist.play();
}