Alen Abraham
Alen Abraham

Reputation: 109

Is there any way to detect live stream buffering on videoview is stopped or not?

i want to check weather the app streaming (live streaming) is buffering or stopped. Is their any way to listen the error while playing the video. i had tried onErrorListner but is detects on if any error occurs during the first time

Upvotes: 1

Views: 1532

Answers (1)

Shubhang Malviya
Shubhang Malviya

Reputation: 1635

I would answer your Question in two parts

  1. I want to check weather the app streaming (live streaming) is buffering or stopped.

You can use VideoView.setOnInfoListener (MediaPlayer.OnInfoListener l) for receiving following Events in your overrided onInfo(MediaPlayer mp, int what, int extra) method .

MEDIA_INFO_BUFFERING_START and MEDIA_INFO_BUFFERING_END for "int what" parameter of onInfo()

For more events , you can take a look here , http://developer.android.com/reference/android/media/MediaPlayer.OnInfoListener.html#onInfo%28android.media.MediaPlayer,%20int,%20int%29

Now 2nd part,

Is their any way to listen the error while playing the video. i had tried onErrorListner but is detects on if any error occurs during the first time

If you take a look at the State Diagram for Media Player here enter image description here

You would find that After Media Player Goes to "Error State" it won't move to any other state , This state can occur for any of the following reasons:

  1. Unsupported audio/video format
  2. Poorly interleaved audio/video
  3. Resolution too high
  4. Streaming timeout, and the like
  5. Sometimes, due to programming errors

Under all these error conditions, the internal player engine invokes a user supplied OnErrorListener.onError() method

Important points to notice from this situation and recovery process can be enumerated as below :

  1. It is important to note that once an error occurs, the MediaPlayer object enters the Error state (except as noted above), even if an error listener has not been registered by the application.
  2. In order to reuse a MediaPlayer object that is in the Error state and recover from the error, reset() can be called to restore the object to its Idle state.
  3. IllegalStateException is thrown to prevent programming errors such as calling prepare(), prepareAsync(), or one of the overloaded setDataSource methods in an invalid state.

You can get more information about all state and Proper handling of media player from this link http://developer.android.com/reference/android/media/MediaPlayer.html

Enjoy !

Upvotes: 3

Related Questions