1

I am streaming audio using MediaPlayer on Android. I want my app to change buffering interval if network is slow i.e. initially cache 5% of song before starting playback than if all cached data already played but new portion is not ready yet cache next 10% and so on. The main point is to avoid song continually stopping and restarting on a slow network.

According to this topic I can't change buffer size for MediaPlayer. Maybe someone has any other idea how I can achieve this?

Thanks in advance.

Community
  • 1
  • 1
Bersh
  • 2,789
  • 3
  • 33
  • 47

1 Answers1

1

Yes, there are not way to change buffer size of MediaPlayer unless you are the hardware driver provider of the device.

The MediaPlayer class is a kind of wrapper to C++ implementation. E.g. if you call myMediaPlayer.seekTo(123) you are calling a C++ method through Java code.

public native void seekTo(int msec) throws IllegalStateException;

Source of android.media.MediaPlayer.seekTo(int).


I recommend you to allow user start the audio after load a certain percentage of buffer.

You can track how many of audio was buffered with onBufferingUpdate(MediaPlayer mp, int percent) listener.

So after prepared state and audio buffer get a certain percent e.g. 50% you could start the audio.

Idemax
  • 2,712
  • 6
  • 33
  • 66