-3

I am using jPlayer plugin. Here is an example link [ jsfiddle ].

I save the current playing track number in a cookie. After a browser reload it starts playing from the track number loaded from the cookie. This works but the problem is, after the current track ends, it starts to play from the first track of the playlist. I want it to continue to the next track.

Example of current situation:

  • playlist have 10 songs
  • clicked on number 3 song
  • cookie saved number 3 song
  • browser reload
  • start playing number 3 song from playlist
  • number 3 song ends
  • start playing from number 1 song

Desired situation:

  • playlist have 10 songs
  • clicked on number 3 song
  • cookie saved number 3 song
  • browser reload
  • start playing number 3 song from playlist
  • number 3 song ends
  • start playing number 4 song
  • number 4 song ends
  • start playing number 5 song
  • ...
alan0xd7
  • 1,831
  • 1
  • 15
  • 19
userknowmore
  • 137
  • 2
  • 14

1 Answers1

2

myPlayer.play() expects an integer value, but when you read from the cookie you get a string. So to fix your problem, just pass the value through parseInt(), like this:

myPlayer.play(parseInt(playnow));

You will notice that on page reload, the proper track will be selected in the playlist as it starts playing, and it will continue to the next track correctly.

Demo: http://jsfiddle.net/alan0xd7/6kx616hr/1/

By the way, I think setInterval with 1 (1 millisecond) is too much, maybe 1000 (1 second) is enough.

alan0xd7
  • 1,831
  • 1
  • 15
  • 19
  • Thanks bro but i want to know what is parseInt()? please vote-up if you did vote-down i have no score to ask any question next... @alan0xd7 – userknowmore Jul 12 '15 at 13:53
  • `parseInt()` converts the value into an `integer`, it is a different data type. An `integer` is a number, while a `string` is a series of letters. – alan0xd7 Jul 12 '15 at 13:57
  • For example: `var a = "1";` and `var b = 1;`, here `a` is a `string` (notice the quotes), and `b` is an `integer`, and `a != b` – alan0xd7 Jul 12 '15 at 13:57
  • Read more about [JavaScript data types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures) – alan0xd7 Jul 12 '15 at 13:58
  • I did not. Maybe next time you could write your question better, so it is more readable. – alan0xd7 Jul 13 '15 at 01:47