Hi,
I just decided to incorporate jPlayer into my site yesterday so I'm a bit new at this and would appreciate some help.
I'm trying to build an audio player that plays songs from a list of songs dynamically generated in the body. I don't want to have a playlist visible, I just want the audio player to automatically play whatever song is clicked in the body and display the title/artist.
I've figured everything out but one thing: After I set the playlist (myPlaylist.setPlaylist) to the new song that is clicked, I use the myPlaylist.play(); to start playing it automatically. But for some reason, it doesn't play. It just sets the song and does nothing. I have to press the play button for it to play.
Here's my code:
<script type="text/javascript">
var myPlaylist=[]; //have to declare this outside of $(document).ready else scope issue with the loadjplayer function
function loadjplayer (mp3URL, title, artist) {
myPlaylist.setPlaylist([{
title: title,
artist: artist,
mp3: mp3URL
}]);
myPlaylist.play(); //this doesn't work for some reason
}
$(document).ready(function (){
myPlaylist = new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
}
, [
]
, {
playlistOptions: {
enableRemoveControls: true
},
swfPath: "/js/jQuery.jPlayer.2.1.0",
supplied: "mp3"
});
$("#jquery_jplayer_1").bind($.jPlayer.event.play, function (event) {
var current = myPlaylist.current,
playlist = myPlaylist.playlist;
$.each(playlist, function (index, obj) {
if (index == current) {
$('.playing_title').text('Playing: ' + obj.title);
$('.playing_artist').text('Artist: ' + obj.artist);
}
});
});
....
I use this in my song list in the body to set/play the player:
<input class="mybutton" value="buble" type="button" onclick="loadjplayer('
http://www.jplayer.org/audio/mp3/TSP-01-Cro_magnon_man.mp3', 'Cro Magnon Man', 'The Stark Palace')">
Any thoughts would be appreciated on why the
myPlaylist.play(); isn't triggering at the function call. Thanks a lot,
Frank