简体   繁体   English

为什么即使在任何地方都没有使用MediaPlayer的情况下,为什么有时仍会在logcat中看到“ MediaPlayer最终完成而没有发布”?

[英]Why do I occasionally see “MediaPlayer finalized without being released” in logcat even though I'm not using MediaPlayer anywhere?

I am, however, using RingtoneManager to get Ringtone s. 但是,我正在使用RingtoneManager来获取Ringtone


This information is already contained in this question and answer , but Googlers are not likely to find it unless they already know what to search for (at least I could not). 此信息已包含在此问答中 ,但是Google员工除非已经知道要搜索的内容(至少我找不到),否则不太可能找到它。

It's because RingtoneManager.getRingtone() internally calls open() on the returned Ringtone object. 这是因为RingtoneManager.getRingtone()内部对返回的Ringtone对象调用open() Ringtone.open() sets up a MediaPlayer , and this MediaPlayer does not get released unless you manually call Ringtone.stop() . Ringtone.open()设置MediaPlayer ,除非您手动调用Ringtone.stop()否则不会释放此MediaPlayer Note that you do not need to actually play the ringtone for this to be true . 请注意, 您无需实际播放铃声即可 This does not appear to be documented anywhere. 这似乎没有记录在任何地方。

I don't know how much actual harm there is in neglecting to release a MediaPlayer (the documentation provides a worst-case scenario), but manually calling stop() on your Ringtone s before letting them get GC'ed will at least silence the warning. 我不知道忽略发布MediaPlayer有多少实际伤害( 文档提供了最坏的情况),但是在让他们获取GC之前在Ringtone上手动调用stop()至少会使沉默警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM