Why Does It Take So Long for Android's Mediaplayer to Prepare Some Live Streams for Playback

Android MediaPlayer.prepare() takes very long time for API 2.3 (Is it because of StageFright?)

Well, after digging around I come up to the conclusion that the loading time depends on the buffer size of the MediaPlayer (which is somehow hardcoded in the firmware) and that there is nothing that can be done to change it.

Android MediaPlayer takes long time to prepare and buffer

I have struggled with this question for months. Finally i found the solution.

The real problem is in the implementation of the MediaPlayer class. Particularly with the way MediaPlayer buffers the data. This is why the solution is to create your own buffering, save it to a temp file and feed that to MediaPlayer.

This tutorial and source code explain exactly how. http://androidstreamingtut.blogspot.nl/2012/08/custom-progressive-audio-streaming-with.html

By adapting this code, it is easy to create a much better streaming player.

Google Developers really screwed up here.

EDIT : This answer is rather old. Nowdays i would recommend not using MediaPlayer and use ExoPlayer instead. It is extendable, stable and can play many different types of media. You can find it here: https://github.com/google/ExoPlayer/

Android MediaPlayer is preparing too long

I think that there are some compatibility problems with the server end.
This is rather strange since the emulator handles it ok in my case - just not on my Froyo Galaxy S, even though it is the same API version.

It could be a codec issue, http streaming issue, I do not know.
But all the servers that fail tend to be old ones, with "Copyright 1998 - 2004" at the bottom... Not exactly recent or up to date you would think.

One potential workaround (which I have not tried yet) would be to use the StreamProxy, which would also make your code compatible with 2.1 and possibly earlier versions too. At the cost of extra work, extra code, and without doubt extra bugs...

In case you are not aware of it, there is another player bug report for 2.2 which may be relevant too:
Basic streaming audio works in 2.1 but not in 2.2

MediaPlayer android stream radio starts not immediately or does not start at all

It seems like audio bitrate might be the key here: https://stackoverflow.com/a/12850965/3454741. There is no easy way to get around this, it seems.

If the streaming does not start at all it might be due to some error, which you could catch using MediaPlayer.setOnErrorListener().

live Streaming audio delays while playing in android-16?

for playing rtsp link you should use sdrPlayer.prepareAsync(); instead of

sdrPlayer.prepare();

because the documentation says

It prepares the player for playback, asynchronously. After setting the datasource and the display surface, you need to either call prepare() or prepareAsync(). For streams, you should call prepareAsync(), which returns immediately, rather than blocking until enough data has been buffered.



Related Topics



Leave a reply



Submit