android – What does MEDIA_ERROR_SERVER_DIED mean?-ThrowExceptions

Exception or error:

In the Android docs, there is a constant defined MEDIA_ERROR_SERVER_DIED which is described as:

Media server died. In this case, the application must release the MediaPlayer object and instantiate a new one.

This seems very vague. What does it mean that the Media server died? Why would it die? And is it proper to handle it by immediately trying to play again afterwards?

How to solve:

In Android, most of media activity (decoding/encoding) happens in the mediaserver, except in limited cases, such as local file playback using software codec. Android mediaserver routinely crashes (aborts) on hardware errors, incorrectly formatted files or data. Yeah, sorry!

Since many activities share a common mediaserver, an error in any of the activities can crash mediaserver. This most commonly happens when a background activity, such as media scanner or Google+ Auto-Awesome Movies tries to scan a corrupt or just unsupported file. When this happens, the remaining processes that used mediaserver receive a notification. This notification is passed to the app in case of MediaPlayer or MediaRecorder.

When mediaserver dies, it is immediately restarted. Even though the server dies, the proxy object on the application is still alive and is using resources. Hence the need to release the object. It should be safe to create a new one immediately after the notification.

###

One condition that causes this is when the MediaPlayer doesn’t receive or stops receiving the video stream from the server. If the error consistently occurs immediately (i.e. if none of the video is received at all), you may want to ensure that nothing (firewall, VPN, etc.) is blocking your route to the server.

###

It means the server from where you are streaming unexpectedly ended the connection. It can happen, usually it’s related to a “Connection reset by peer” error.

You could try to reconnect yes, maybe after waiting a bit.

Leave a Reply

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