Sorry that last post posted early.

The basic issue is that I am using MediaPlayer to play music for an
alarm clock.  If the user backs out of the app or turns the alarm off
via a UI switch everything seems fine as long as they do it within two
minutes or so.  If they wait four or five minutes or more, I get that
darned Sorry! message that it finished unexpectedly.

Regardless of my disagreement with the Operating System about the fact
that the activity finished when the user pressed the back button,
which is exactly my definition of 'expectedly', something is obviously
not right.

I'm guessing the MediaPlayer is leaking, but how do I debug  this
since the error message only shows up after the activity closes?
Finish is called and I clear out the mediaPlayer in OnBackPressed()
with:

        if(timer != null)
                timer.cancel();
        if(alarmPlayer != null)
        {
                alarmPlayer.stop();
                alarmPlayer.release();
        }
        super.onBackPressed();

A) Should super.onBackPressed be before this code or does it matter?
Is this the right way to do onBackPressed to release the MediaPlayer?

B) Here is how I am creating the MediaPlayer in the activity’s
onCreate method:

alarmPlayer = MediaPlayer.create(this, musicResId);
alarmPlayer.setVolume(masterVolume, masterVolume);
alarmPlayer.setLooping(true);
alarmPlayer.start();
long period = timeIncrementReached;// in ms
timer = new Timer();
 AlarmVolumeIncreaser increaser = new AlarmVolumeIncreaser();
timer.schedule( increaser, 0, period);


And then the AlarmVolumeIncreaser is a runnable like so:

class AlarmVolumeIncreaser extends TimerTask
{
@Override
public void run()
{
If(masterVolume < 1.0f)
{
masterVolume += .01f;
alarmPlayer.setVolume(masterVolume, masterVolume);
}
}
}

Is this the right way to do play music that increases in volume over
time?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to