jplayer auto play shoutcast stream? not working!

1,167 views
Skip to first unread message

Jonny

unread,
Dec 9, 2013, 11:19:04 AM12/9/13
to jpl...@googlegroups.com
Hi everyone,

I've been trying out the Jplayer and it's absolutely lovely, however i can't get the auto play functions to work.

Here's my code:

<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){

    var stream = {
        title: "Trance, Progressive, Chillout Radio",
        mp3: "http://jonnyeriksson.com:8000/;stream/1"
    },
    ready = false;

    $("#jquery_jplayer_1").jPlayer({
        ready: function (event) {
            ready = true;
            $(this).jPlayer("setMedia", stream);
        },
        pause: function() {
            $(this).jPlayer("clearMedia");
        },
        error: function(event) {
            if(ready && event.jPlayer.error.type === $.jPlayer.error.URL_NOT_SET) {
                // Setup the media stream again and play it.
                $(this).jPlayer("setMedia", stream).jPlayer("play");
            }
        },
        swfPath: "js",
        supplied: "mp3",
        preload: "auto",
        wmode: "window",
        keyEnabled: true
    });

});
//]]>
</script>

I've tried with the autoplay: true as option but does absolutely nothing, any ideas?

Thanks!

Mark Panaghiston

unread,
Dec 9, 2013, 11:52:07 AM12/9/13
to jpl...@googlegroups.com
In the ready function there is this line:

$(this).jPlayer("setMedia", stream);

Replace it with this line (which you will notice is in the error event to reconnect and auto play):


$(this).jPlayer("setMedia", stream).jPlayer("play");

The problem you might encounter with this is that mobile devices will be told to play the stream, but then ignore the command. The gui should recover and return to the play icon since it is not playing.

The other thing, return the preload option does not matter much if you are trying to auto play... Ya canae preload it if ya gunae play it. I'd leave it at the default "metadata".

Jonny

unread,
Dec 9, 2013, 12:12:35 PM12/9/13
to jpl...@googlegroups.com
Thanks, works perfectly! i was reading on the support for jplayer and for some reason i was looking at this line:        

 error: function(event) {
            if(ready && event.jPlayer.error.type === $.jPlayer.error.URL_NOT_SET) {
                // Setup the media stream again and play it.
                $(this).jPlayer("setMedia", stream).jPlayer("play");

And i though , hmm i already have the "play" setting, no wonder :) Looking at the wrong function, thanks man, it's been a long day !
Reply all
Reply to author
Forward
0 new messages