Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to .release() the MediaPlayer instantiated by RingtoneManager?

I'm getting a default Ringtone in my Activity:

remindRingtoneView = (TextView) findViewById(R.id.remind_ringtone);

remindRingtoneView.setText(RingtoneManager.getRingtone(
            NewReminder.this, ringtone_uri).getTitle(
            NewReminder.this));

After this line I've got a debug line in LogCat with tag = 'Ringtone' and message =

'Successfully created a local player'.

When I finished Activity and system garbage collector do it's good job I got a warn message in LogCat =

'MediaPlayer finalized without being released'.

How I can release it?

Answer is:

Ringtone remind_ringtone = RingtoneManager.getRingtone(
            NewReminder.this, ringtone_uri);        
remindRingtoneView.setText(remind_ringtone.getTitle(NewReminder.this));
remind_ringtone.stop();
like image 389
Sergey Grabak Avatar asked Dec 01 '25 12:12

Sergey Grabak


1 Answers

In your program, RingtoneManager.getRingtone will return an object to Ringtone class. If we consider this object to be mRingTone, then invoking mRingTone.stop() will release the MediaPlayer object.

like image 85
Ganesh Avatar answered Dec 04 '25 01:12

Ganesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!