android播放音视频使用mediaplayer不规范导致的电流过高问题
2014-01-12 12:07
519 查看
在使用mediaplayer等多媒体相关的类进行多媒体应用开发的时候,建议各位小伙伴仔细阅读sdk,按照标准使用,曾经遇到一个问题,某某同学在修改音视频code时,为了方便,在activity的onPause()和onStop()时并未进行资源的回收,即调用mediaplayer的release()方法释放,这样,在重新onResume()或者onStart()的时候就不需要重新new实例,重新设置Uri等一系列操作,看起来是方便许多,其实这里隐藏这一个较大的问题,查看sdk,可以看到如下一段话:
Added in API level 1
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.
如果不释放,在应用长期后台的情况下,待机电流过高或者media中的codec实例被过度消耗导致其他应用播放失败, 手机性能降低等等一系列问题,在debug时也难以分析,只有痛苦的review代码,原本很多只是多阅读一下api的问题,却要耗费大量时间debug,真是得不偿失,OEM厂商在只能控制内置应用的规范,如果因为三方软件的不规范开发导致的电流过高或者其他应用异常,导致待机时间减少,手机厂商就是真的躺枪了,android的碎片化已经是一个客观存在的问题,我们只能要求自己有良好的编程习惯了。。。
public void release ()
Added in API level 1Releases 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.
如果不释放,在应用长期后台的情况下,待机电流过高或者media中的codec实例被过度消耗导致其他应用播放失败, 手机性能降低等等一系列问题,在debug时也难以分析,只有痛苦的review代码,原本很多只是多阅读一下api的问题,却要耗费大量时间debug,真是得不偿失,OEM厂商在只能控制内置应用的规范,如果因为三方软件的不规范开发导致的电流过高或者其他应用异常,导致待机时间减少,手机厂商就是真的躺枪了,android的碎片化已经是一个客观存在的问题,我们只能要求自己有良好的编程习惯了。。。
相关文章推荐
- android列表中使用MediaPlayer播放视频的一个问题
- [OpenGL]从零开始写一个Android平台下的全景视频播放器——2.3 使用GLSurfaceView和MediaPlayer播放一个平面视频(下)
- android 使用mediaplayer播放报java.io.IOException: setDataSourceFD failed.: status=0x80000000的问题
- [OpenGL]从零开始写一个Android平台下的全景视频播放器——2.2 使用GLSurfaceView和MediaPlayer播放一个平面视频(中)
- android-MediaPlayer的基本使用-播放音频视频
- [OpenGL]从零开始写一个Android平台下的全景视频播放器——2.1 使用GLSurfaceView和MediaPlayer播放一个平面视频(上)
- 从头学Android之多媒体--使用MediaPlayer和SurfaceView播放视频
- android 使用mediaplayer播放视频的时候设置请求头header
- android 使用webview访问优酷无法播放视频的问题
- 28、从头学Android之多媒体--使用MediaPlayer和SurfaceView播放视频
- 从头学Android之多媒体--使用MediaPlayer和SurfaceView播放视频
- Android 使用MediaPlayer播放视频切换后台暂停再恢复互前台继续播放的bug修改
- Android之使用MediaPlayer和SurfaceView组件播放一个简单的视频
- Android 使用Webview无法播放视频问题的解决办法
- Android 使用MediaPlayer与SurfaceView进行视频播放
- Android使用MediaPlayer播放视频
- 解决Android使用SurfaceView播放视频结束后黑屏问题
- Android 使用MediaPlayer 播放 视频
- android 使用MediaPlayer实现视频播放
- Android里面使用MediaPlayer通过SurfaceView播放视频的示例