jPlayerPlaylist myPlaylist.play() command doesn't trigger after setting myPlaylist.setPlaylist in function

Showing 1-3 of 3 messages
jPlayerPlaylist myPlaylist.play() command doesn't trigger after setting myPlaylist.setPlaylist in function Frank 2/17/12 12:02 PM
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
Re: jPlayerPlaylist myPlaylist.play() command doesn't trigger after setting myPlaylist.setPlaylist in function Schyzophrenic 7/1/12 4:55 AM
I have the exact same issue and I really can't understand this behavior. 
I can see that this is quite old now, have you found, by any chance, a solution or a workaround ?

Thanks for your help

Le vendredi 17 février 2012 21:02:57 UTC+1, Frank a écrit :
Re: jPlayerPlaylist myPlaylist.play() command doesn't trigger after setting myPlaylist.setPlaylist in function Oritm 9/24/12 4:04 AM
Im not sure if you solved it, but after init the playlist object, do something like

myPlaylist.option("autoPlay", true);