Hello,

I'm using a MediaPlayer instance to stream mp3s over a local proxy
server. For the MediaPlayer I've registered info, error, and
completion callbacks. This proxy server knows the full file length of
the stream that it's downloading and it maintains the number of bytes
it transferred. If there's a connection interruption that results in a
failed transfer, I want to recover from this by requesting the failed
bytes with an HTTP range request.

Using a range request, I'm able to recover the actual file download.
However, the MediaPlayer itself quickly times out when it stops
receiving bytes. This is the logcat output I see when this happens:

E/HTTPStream(   68): recv failed, errno = 11 (Try again)
E/NuCachedSource2(   68): source returned error -1004

When the MediaPlayer hits the spot in the stream where it timed out—
when the above was logged—it stops playing, and calls its onComplete
callback. At no time is the info or error callback called.

At this point I want to know if the song really did play until
completion. I added code in this callback to compare the completed
MediaPlayer's current position to its duration, accessed with
getCurrentPosition() and getDuration() respectively. If the current
position is less than the total duration, I call prepare() again, and
once prepared, seek to the position returned by getCurrentPosition().
This works absolutely wonderfully on the Nexus One. There's less than
a second of audio interruption, and the song continues playing as
normally; you hardly even notice the hiccup.

However, on some phones, notably the Droid II Global, the MediaPlayer
often misreports a song's duration, sometimes it's incorrect by more
than a minute. See this screenshot for comparison:
http://s1-04.twitpicproxy.com/photos/large/429522852.png the Nexus One
is on the right, and the Droid II Global is on the left. So comparing
a song's current position to its duration isn't a reliable way to know
if it played to its full duration.

I also tried using the song's buffered amount, obtained by registering
a buffer update listener. Unfortunately, as soon as the song plays to
its buffered amount—to the part of the file where the connection was
lost—the buffered amount immediately updates to 100%, so I cannot use
this value either.

Is there a reliable way to determine if a MediaPlayer datasource
played to its full length?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to