Set buffering times

The MediaPlayer provides methods to set and get the buffer control parameters.

If you do not set the buffer control parameters before beginning playback, the media player defaults to 2 seconds for the initial buffer and 30 seconds for the buffer time.

  1. Set up the BufferControlParameters object, which encapsulates the control parameters (the initial buffer time and play buffer time). This class provides two factory methods:
    • public static BufferControlParameters createSimple(long bufferTime) (in this case the initial buffer time is equal to the buffer time)
    • public static BufferControlParameters createDual(long initialBuffer, long bufferTime)

    These methods throw an IllegalArgumentException if the parameters are not valid, such as when:

    • The initial buffer time is lower than zero
    • The initial buffer time is bigger than the buffer time
  2. To set the buffer parameters:
    void setBufferControlParameters(BufferControlParameters params)
  3. To get the current buffer parameter values:
    BufferControlParameters getBufferControlParameters() 
    

    If the AVE cannot set the specified values, the media player enters the ERROR state. The error code is SET_BUFFER_PARAMETERS_ERROR.

For example, to set the initial buffer to 5 seconds and the buffer time to 30 seconds:

mediaPlayer.setBufferControlParameters(BufferControlParameters.createDual(5000, 30000));

The PMPDemoApp demonstrates this feature; use the application’s settings to set the buffer values.