2022-05-30
释放与mediaplayer对应有关的资源。使用完mediaplayer之后调用这个方法是一个好的习惯。尤其是,任何时候一个应用的activity暂停或停止了(它的onPause或者onStop方法被调用了),这个方法都应该被调用来释放mediaplayer的对象,除非应用需要持有这个对应作为特殊需要。
除此之外,不必要的资源(如内存和编译器实例)被持有,如果mediaplayer对象不再需要,立马调用这个方法失败,也会导致移动设备的持续电量消耗,如果设备上同一编译器不支持多实例,会导致其他应用播放失败。
即使同一编译器是支持多实例化,当同一时间内使用多个不必要的实例,预期会造成性能上的恶化。
Releases resources associated with this MediaPlayer object. It is considered good practice to call this method when you're done using the MediaPlayer.
In particular, whenever an Activity of an application is paused (its onPause() method is called), or stopped (its onStop() method is called), this method should be invoked to release the MediaPlayer object, unless the application has a special need to keep the object around.
In addition to unnecessary resources (such as memory and instances of codecs) being held, failure to call this method immediately if a MediaPlayer object is no longer needed may also lead to continuous battery consumption for mobile devices, and playback failure for other applications if no multiple instances of the same codec are supported on a device.
Even if multiple instances of the same codec are supported, some performance degradation may be expected when unnecessary multiple instances are used at the same time.