Release PlaybackController in onDestroy() method in MediaplayerActivity
This commit is contained in:
parent
ff364f13f9
commit
14d05bde1c
@ -186,7 +186,16 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity
|
|||||||
super.onStop();
|
super.onStop();
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Activity stopped");
|
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
|
@Override
|
||||||
|
@ -55,6 +55,7 @@ public abstract class PlaybackController {
|
|||||||
protected ScheduledFuture positionObserverFuture;
|
protected ScheduledFuture positionObserverFuture;
|
||||||
|
|
||||||
private boolean mediaInfoLoaded = false;
|
private boolean mediaInfoLoaded = false;
|
||||||
|
private boolean released = false;
|
||||||
|
|
||||||
public PlaybackController(Activity activity) {
|
public PlaybackController(Activity activity) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
@ -83,7 +84,12 @@ public abstract class PlaybackController {
|
|||||||
* activity's onResume() method.
|
* activity's onResume() method.
|
||||||
*/
|
*/
|
||||||
public void init() {
|
public void init() {
|
||||||
bindToService();
|
if (!released) {
|
||||||
|
bindToService();
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Can't call init() after release() has been called");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,7 +117,7 @@ public abstract class PlaybackController {
|
|||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
activity.unregisterReceiver(shutdownReceiver);
|
activity.unregisterReceiver(shutdownReceiver);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@ -120,6 +126,7 @@ public abstract class PlaybackController {
|
|||||||
cancelPositionObserver();
|
cancelPositionObserver();
|
||||||
schedExecutor.shutdownNow();
|
schedExecutor.shutdownNow();
|
||||||
media = null;
|
media = null;
|
||||||
|
released = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,7 +541,6 @@ public abstract class PlaybackController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getDuration() {
|
public int getDuration() {
|
||||||
if (playbackService != null) {
|
if (playbackService != null) {
|
||||||
return playbackService.getDurationSafe();
|
return playbackService.getDurationSafe();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user