0

I am able to stream songs from Grooveshark using there public streaming API. I am using this with jPlayer(jplayer.org) and it's streaming the songs correctly.

But the problem is that in Firefox (checked on latest version) the full duration of the song keeps on increasing from 00:00 to the full song length. Basically the full song duration is the amount of the song buffered.

For e.g. a song of length 04:00 minutes starts buffering. Now when it buffers a quarter of the song (i.e. 01:00 minutes), jPlayer shows the song duration as 01:00 minutes whereas it should be 04:00 minutes.

Screenshot: (The song playing has total length 05:06 minutes)

https://i.stack.imgur.com/wzxPx.png

In Google Chrome (checked on latest version) the full duration of the song is shown and jplayer shows that the whole song is buffered even from the start of the song.

Screenshot: (Chrome shows that the full song is buffered but it is still buffering)

https://i.stack.imgur.com/PSkct.png

jPlayer uses HTML5 first and falls back to flash if HTML5 not supported. Google Chrome supports playing mp3 using HTML5 (Grooveshark stream is an mp3). But Firefox does not supports mp3 in HTML5.

So it is clear that Firefox is using flash and Chrome is using HTML5.

Now the problems I want to solve are :-

  • Getting full duration of song in Firefox and keep everything else like it is.
  • Keeping the full duration of song in Chrome and to show the correct amount of song buffered.

All of this should be possible as grooveshark website itself also uses the same stream.php file.

Grooveshark is also providing it's own flash player but it does not has enough features and specially it's not HTML5.

And if it's not possible with jPlayer then please suggest me a better alternative that supports HTML5 and is good for streaming.

  • Look at http://stackoverflow.com/questions/13170411/audio-element-with-controls-trackbar-not-moving for similar issue – Baba Feb 12 '13 at 08:13
  • @Baba I do not have control of the stream.php as it is at Grooveshark's end. And when I check the headers of stream.php in Firebug, the header for Content-Length is already set. – Anshuman 'xLR' Verma Feb 12 '13 at 08:40

1 Answers1

0

One thing you can do, which Grooveshark does sometimes, is take the current length of the song and divide it by the percentage loaded. This will give you a good estimate to the actual duration of the file except for possibly VBR files. You can also try looking at the ID3 tags.

James Hartig
  • 1,009
  • 1
  • 9
  • 20
  • Thanks James. I used these methods and Javascript was unable to read the ID3 tags because the link was cross domain. With PHP I was only able to get the ID3 tags by downloading the song through curl temporarily to a local directory and then getting its ID3 tags. This method won't be good for long term. And when trying to use currentLength/percentLoaded method. This does not returns an exact value and differs by like 0-6 seconds. Is there any method in the Grooveshark API that can return the song duration or is it possible to have such a method in future? – Anshuman 'xLR' Verma Feb 13 '13 at 12:13
  • Ok got the problem. The file I was checking the currentLength/percentLoaded method was VBR and as you said it won't work for VBR files. Checked the same song on Grooveshark.com and the duration is shown wrong there too. CBR files working fine. Marking as correct Answer ... Thanks a lot ! It would be better if the Grooveshark API returns the song duration with the other song information to get over this issue for VBR files. – Anshuman 'xLR' Verma Feb 15 '13 at 09:35
  • Unfortunately we don't have the song duration on the backend. For some files we have an estimate of the duration and when we can we use the estimate duration. You should get something from the API for the files that we have an estimate duration from. – James Hartig Feb 16 '13 at 20:10