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

824 views
Skip to first unread message

Frank

unread,
Feb 17, 2012, 3:02:57 PM2/17/12
to jpl...@googlegroups.com
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

Schyzophrenic

unread,
Jul 1, 2012, 7:55:00 AM7/1/12
to jpl...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages