Actually stop PlaybackService

This commit is contained in:
ByteHamster 2018-07-13 09:23:36 +02:00
parent cc645c5fb1
commit 53a3b85272
1 changed files with 15 additions and 9 deletions

View File

@ -341,6 +341,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
Log.d(TAG, "Service is about to be destroyed"); Log.d(TAG, "Service is about to be destroyed");
stopForeground(true);
isRunning = false; isRunning = false;
started = false; started = false;
currentMediaType = MediaType.UNKNOWN; currentMediaType = MediaType.UNKNOWN;
@ -364,6 +365,11 @@ public class PlaybackService extends MediaBrowserServiceCompat {
taskManager.shutdown(); taskManager.shutdown();
} }
private void stopService() {
stopForeground(true);
stopSelf();
}
@Override @Override
public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid, Bundle rootHints) { public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid, Bundle rootHints) {
Log.d(TAG, "OnGetRoot: clientPackageName=" + clientPackageName + Log.d(TAG, "OnGetRoot: clientPackageName=" + clientPackageName +
@ -458,7 +464,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE); Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE);
if (keycode == -1 && playable == null && !castDisconnect) { if (keycode == -1 && playable == null && !castDisconnect) {
Log.e(TAG, "PlaybackService was started with no arguments"); Log.e(TAG, "PlaybackService was started with no arguments");
stopSelf(); stopService();
return Service.START_NOT_STICKY; return Service.START_NOT_STICKY;
} }
@ -470,7 +476,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
Log.d(TAG, "Received media button event"); Log.d(TAG, "Received media button event");
boolean handled = handleKeycode(keycode, true); boolean handled = handleKeycode(keycode, true);
if (!handled) { if (!handled) {
stopSelf(); stopService();
return Service.START_NOT_STICKY; return Service.START_NOT_STICKY;
} }
} else if (!flavorHelper.castDisconnect(castDisconnect) && playable != null) { } else if (!flavorHelper.castDisconnect(castDisconnect) && playable != null) {
@ -680,7 +686,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
case STOPPED: case STOPPED:
//writePlaybackPreferencesNoMediaPlaying(); //writePlaybackPreferencesNoMediaPlaying();
//stopSelf(); //stopService();
break; break;
case PLAYING: case PLAYING:
@ -697,7 +703,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
case ERROR: case ERROR:
writePlaybackPreferencesNoMediaPlaying(); writePlaybackPreferencesNoMediaPlaying();
stopSelf(); stopService();
break; break;
} }
@ -710,7 +716,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
@Override @Override
public void shouldStop() { public void shouldStop() {
stopSelf(); stopService();
} }
@Override @Override
@ -759,7 +765,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
} }
sendNotificationBroadcast(NOTIFICATION_TYPE_ERROR, what); sendNotificationBroadcast(NOTIFICATION_TYPE_ERROR, what);
writePlaybackPreferencesNoMediaPlaying(); writePlaybackPreferencesNoMediaPlaying();
stopSelf(); stopService();
return true; return true;
} }
@ -1213,7 +1219,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
if (playable == null) { if (playable == null) {
Log.d(TAG, "setupNotification: playable is null"); Log.d(TAG, "setupNotification: playable is null");
if (!started) { if (!started) {
stopSelf(); stopService();
} }
return; return;
} }
@ -1227,7 +1233,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
if (mediaPlayer == null) { if (mediaPlayer == null) {
Log.d(TAG, "notificationSetupTask: mediaPlayer is null"); Log.d(TAG, "notificationSetupTask: mediaPlayer is null");
if (!started) { if (!started) {
stopSelf(); stopService();
} }
return; return;
} }
@ -1548,7 +1554,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (TextUtils.equals(intent.getAction(), ACTION_SHUTDOWN_PLAYBACK_SERVICE)) { if (TextUtils.equals(intent.getAction(), ACTION_SHUTDOWN_PLAYBACK_SERVICE)) {
stopSelf(); stopService();
} }
} }