android – change buffer size on MediaPlayer-ThrowExceptions

Exception or error:

is there any way to change default buffer size on streaming MediaPlayer?

How to solve:

The buffer size is baked into the firmware. All you can do is keep tabs on how much the buffer is filled, and even that is just on a percentage basis.

Sorry!

###

The size is set in frameworks/base/media/libstagefright/include/NuCachedSource2.h

kDefaultHighWaterThreshold and kDefaultLowWaterThreshold went up between Android 2.3.7 and Android 4.0.4
The buffer size grew by the factor 8, like stated in this thread
Android – MediaPlayer Buffer Size in ICS 4.0

You would need a custom rom.

Android 2.3.7

enum {
    kPageSize            = 65536,
    kHighWaterThreshold  = 5 * 1024 * 1024,
    kLowWaterThreshold   = 512 * 1024,

    // Read data after a 15 sec timeout whether we're actively
    // fetching or not.
    kKeepAliveIntervalUs = 15000000,
};

Android 4.0.4

enum {
    kPageSize                       = 65536,
    kDefaultHighWaterThreshold      = 20 * 1024 * 1024,
    kDefaultLowWaterThreshold       = 4 * 1024 * 1024,

    // Read data after a 15 sec timeout whether we're actively
    // fetching or not.
    kDefaultKeepAliveIntervalUs     = 15000000,
};

If you mind this issue, then maybe you are interested in the bug report
https://code.google.com/p/android/issues/detail?id=29870

###

This may be not entirely relevant to your specific problem, but maybe somebody else will be helped by this:

I just need to know how big the buffer is. I guess it is a fixed amount of bytes,rather than a fixed amount of playback time.

To get an estimate of the audio/video buffer size, you can implement a OnBufferingUpdateListener to detect when the buffer is completely filled, and use TrafficStats to determine how many bytes your streaming media has consumed between starting the stream and the buffer getting full. This should be an indicator of the size of the buffer MediaPlayer uses…

###

The problem appears when streaming live content, example: live internet radio. As live content I can’t calculate nothing because track length is infinite and onBuffering methods in MediaPlayer are never called.

My intention is set a buffer depending on bitrate factor to optimize resources and increase it to prevent 3G disconnections. Well, really I can’t prevent 3G disconnections, but I want to mean that I can make this connection longer to keep streaming more alive to end-user.

So I think I can code a Java proxy to connect to live content and set my own buffer size depending on bitrate, then pass this proxy as url on MediaPlayer and play the content.

But before start coding this, I want to know if there is another method, or another better trick that I can apply to MediaPlayer to solve this issue.

Leave a Reply

Your email address will not be published. Required fields are marked *