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.