Release PlaybackController in onDestroy() method in MediaplayerActivity

This commit is contained in:
daniel oeh 2012-09-26 12:51:59 +02:00
parent ff364f13f9
commit 14d05bde1c
2 changed files with 19 additions and 4 deletions

View File

@ -186,7 +186,16 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity
super.onStop();
if (AppConfig.DEBUG)
Log.d(TAG, "Activity stopped");
controller.release();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (AppConfig.DEBUG)
Log.d(TAG, "Activity destroyed");
if (controller != null) {
controller.release();
}
}
@Override

View File

@ -55,6 +55,7 @@ public abstract class PlaybackController {
protected ScheduledFuture positionObserverFuture;
private boolean mediaInfoLoaded = false;
private boolean released = false;
public PlaybackController(Activity activity) {
this.activity = activity;
@ -83,7 +84,12 @@ public abstract class PlaybackController {
* activity's onResume() method.
*/
public void init() {
bindToService();
if (!released) {
bindToService();
} else {
throw new IllegalStateException(
"Can't call init() after release() has been called");
}
}
/**
@ -120,6 +126,7 @@ public abstract class PlaybackController {
cancelPositionObserver();
schedExecutor.shutdownNow();
media = null;
released = true;
}
@ -534,7 +541,6 @@ public abstract class PlaybackController {
}
}
public int getDuration() {
if (playbackService != null) {
return playbackService.getDurationSafe();