2

I sometimes (not every time) get this warning "Media player finalized before being released" in LogCat, and the sound is played only partially (cuts off).

I have a service CountdownService, and there I have:

MyApplication appActivity = (MyApplication)this.getApplication();
appActivity.playCountdownComplete();
stopSelf(); // I absolutely must stop the service at this point

And in the MyApplication (extends Application) activity I have:

public void playCountdownComplete() {
    MediaPlayer mp = MediaPlayer
                     .create(getApplicationContext(), R.raw.sound_complete);
    mp.setOnCompletionListener(new OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            mp.release();
        }
    });
    mp.start();
}

I absolutely must stop the service at the point where I call stopSelf(); because my app depends on the service not running, so please do not offer a solution that changes that.

Why doesn't the sound play completely? - the application activity is playing the sound, so even if the service is stopped, it shouldn't matter, right?

EDIT: I also tried having the service send out a broadcast and the Application activity receiving it and playing the sound there, but still the same thing happens.

Reactgular
  • 52,335
  • 19
  • 158
  • 208
PFort
  • 485
  • 2
  • 6
  • 15
  • 1
    I guess the problem is in MediaPlayer declaration, similar to [this](http://stackoverflow.com/questions/15023037/garbage-collection-causes-mediaplayer-finalized-without-being-released) one. – user3158941 Jan 03 '14 at 22:33

0 Answers0