is there any way to change default buffer size on streaming MediaPlayer
?
4 Answers
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!

- 986,068
- 189
- 2,389
- 2,491
-
2Not really / only. As I saw in Googles Code there is a Method `public booleansetParameter(int key, int value)` which lets you do this if you know the value for key (I have them for RK devices). Unfortunately I can't find a way to call this method (though it is public), but I will find it, there must be a way to do this! – paulgavrikov Dec 21 '13 at 17:33
-
@bluewhile did you find a way to do this? – w2lame Aug 27 '14 at 14:33
-
3No I ended up crying because I lost several big deals just because of Googles ignorance. – paulgavrikov Aug 27 '14 at 21:23
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...

- 51
- 1
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.

- 333
- 1
- 3
- 8