
我有两个按钮和两首歌.按钮1初始化并播放歌曲1.与按钮2和歌曲2相同.
因此,在单击时,按钮1使用create,setDataSource,prepare和start方法.
那么,重置和释放方法有什么区别?
按钮2应该使用reset,create,setDataSource,准备和启动
OR release,create,setDataSource,准备然后启动?
对于我的测试,它完全相同……
解决方法:
从API docs(我强烈建议你阅读):
发布():
Releases resources associated with this MediaPlayer object. It is consIDered good practice to call this method when you’re done using the MediaPlayer. In parti@R_403_6603@r, 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.
重启():
resets the MediaPlayer to its uninitialized state. After calling this method, you will have to initialize it again by setting the data source and calling prepare().
因此,基于此,您应该调用reset()而不是release(),因为您在播放歌曲后仍然需要该对象.
总结以上是内存溢出为你收集整理的android – MediaPlayer重置和释放之间的区别全部内容,希望文章能够帮你解决android – MediaPlayer重置和释放之间的区别所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)