Release a MediaPlayer instance and resources

Release a MediaPlayer instance and resources when you no longer need the MediaResource.

Releasing a MediaPlayer object deallocates the underlying hardware resources associated with this MediaPlayer object. Release a MediaPlayer when it is no longer useful. For several reasons, it is good practice to do this:
  • Holding unnecessary resources can affect performance.
  • Leaving an unneeded MediaPlayer object can lead to continuous battery consumption for mobile devices.
  • Playback failure might occur for other applications if multiple instances of the same video-codec are not supported on a device.
Call the release method:
void release() throws IllegalStateException;
After the MediaPlayer instance is released, you can no longer use it. Calling any method of the MediaPlayer interface after it is released results in an IllegalStateException being thrown.