如何释放由RingtoneManage实例化的MediaPlayer
为了获取android铃声的名称,使用了以下代码
//根据铃声地址获取铃声的名称
public String getRingtonName(Uri uri)
{
Ringtone r= RingtoneManager.getRingtone(getActivity(), uri);
String toneName = r.getTitle(getActivity());
return toneName;
}
调用该方法后,LogCat里提示:
'Successfully created a local player'.
接着又有个Warning:
'MediaPlayer finalized without being released'.
如何消除这个警告呢?使用
Ringtone的stop方法。
修改后的代码如下:
//根据铃声地址获取铃声的名称
public String getRingtonName(Uri uri)
{
Ringtone r= RingtoneManager.getRingtone(getActivity(), uri); //会提示Successfully created a local player
String toneName = r.getTitle(getActivity());
r.stop();//避免出现MediaPlayer finalized without being released
return toneName;
}