What does MEDIA_ERROR_SERVER_DIED mean?

yydl picture yydl · Dec 2, 2011 · Viewed 10k times · Source

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?

Answer

Lajos Molnar picture Lajos Molnar · Apr 7, 2014

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.