Trushar Narodia
Trushar Narodia

Reputation: 366

preload next song before end of the current song

i have one issue related jplayer. i am using jplayer for play song in my site right now i am fetching song using ajax call and add that song into jplayer playlist and now its working fine

my question is is there any option to ready next song before end of current song because when i try it with less then 1 minute song its working fine but when i have each song duration more then 4 minutes its take 3 to 4 seconds to load new song

this is my code for load song in jpalyer playlist

// for create jplayer and add song in playlist
function play_music(songobj) {
    is_play = 1;
    // $("#jquery_jplayer_1").jPlayer("destroy");
    var playlist_length = songobj.length;
    myPlaylist = new jPlayerPlaylist({
      jPlayer: "#jquery_jplayer_1",
      cssSelectorAncestor: "#jp_container_N"
    },songobj, {
      playlistOptions: {
        enableRemoveControls: true,
        autoPlay: true
      },
      supplied: "oga, mp3",
      wmode: "window",
      useStateClassSkin: true,
      autoBlur: false,
      smoothPlayBar: true,
      keyEnabled: true,
      ended : function(){
        if(playlist_length == currlength){
                // alert('end playlist');
                is_play = 0
                location.reload();
              }
              else{                  
                /*if( == ){
                  console.log('yesssssss');
                }*/
                // console.log(play_index[index_key]);
                // console.log(playlist_obj[currlength]);
                loop = 1;
                currlength += 1;
                var songindex = song_index[currlength - 1];
                  var listindex = playlist_obj[index_key];
                  if(song_index[currlength - 1] == playlist_obj[index_key]){
                    index_key += 1;
                    $("#jquery_jplayer_1").jPlayer("pause", 0);
                    console.log('playlist over start next');
                    setTimeout(function() {
                      $("#jquery_jplayer_1").jPlayer("play", 0);
                    }, $('#timeout').val()*1000);
                  }
              }

            },
          });
  }

also if there are any options for preload all song before play, please guide me this is very important for me thanks

Upvotes: 1

Views: 521

Answers (1)

Martin Dawson
Martin Dawson

Reputation: 7656

Behind the scenes their is only one audio source even for playlist. jPlayer & jPlaylist are just wrappers.

This means that you can't load the next song before the current ends because that would require changing the audio source which would change the song.

Their is no built in way to do this. Maybe their is a way such as having another hidden jPlayer on the page and load the next song and somehow copying the data over without having to load but I am not sure and you probably shouldn't even have to do this.

3-4 seconds to load seems weird though, it should only load the metadata as default and in the below example for a 5 min+ song it's 46KB...

Maybe their is something wrong with your .mp3, .ogg urls. Can you post them?

This loads instantly for example: http://jsfiddle.net/Ls8p90y9/175/

$("#jquery_jplayer_1").jPlayer({
    ready: function () {
        $(this).jPlayer("setMedia", {
            title: "Bubble",
            mp3: "http://www.jplayer.org/audio/mp3/Miaow-01-Tempered-song.mp3"
        });
    },
    timeupdate: function(event) {
        $("#jp_container_1 .jp-ball").css("left",event.jPlayer.status.currentPercentAbsolute + "%");
    },
    supplied: "mp3",
});

Try messing with the preload option:

preload

String : (Default: "metadata") : Valid values are "none", "metadata" and "auto", which matches the HTML5 draft standard. Use "auto" to preload the file. Preload is a hint to the user agent, not a command. Some browsers ignore this option.

Upvotes: 1

Related Questions