Don't stop service between episodes (#6293)
This commit is contained in:
parent
efcb710703
commit
731adeaf2c
|
@ -760,13 +760,9 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
taskManager.startChapterLoader(newInfo.playable);
|
||||
break;
|
||||
case PAUSED:
|
||||
if (UserPreferences.isPersistNotify() || isCasting) {
|
||||
// do not remove notification on pause based on user pref
|
||||
// Change [Play] button to [Pause]
|
||||
updateNotificationAndMediaSession(newInfo.playable);
|
||||
} else if (!UserPreferences.isPersistNotify() && !isCasting) {
|
||||
// remove notification on pause
|
||||
stateManager.stopForeground(true);
|
||||
updateNotificationAndMediaSession(newInfo.playable);
|
||||
if (!isCasting) {
|
||||
stateManager.stopForeground(!UserPreferences.isPersistNotify());
|
||||
}
|
||||
cancelPositionObserver();
|
||||
PlaybackPreferences.writePlayerStatus(mediaPlayer.getPlayerStatus());
|
||||
|
@ -811,7 +807,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
|
||||
@Override
|
||||
public void shouldStop() {
|
||||
updateNotificationAndMediaSession(getPlayable()); // Stops foreground if not playing
|
||||
stateManager.stopForeground(!UserPreferences.isPersistNotify());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1271,7 +1267,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
|
||||
notificationManager.notify(R.id.notification_playing, notificationBuilder.build());
|
||||
startForegroundIfPlaying(playerStatus);
|
||||
|
||||
if (!notificationBuilder.isIconCached()) {
|
||||
playableIconLoaderThread = new Thread(() -> {
|
||||
|
@ -1286,21 +1281,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
}
|
||||
}
|
||||
|
||||
private void startForegroundIfPlaying(@NonNull PlayerStatus status) {
|
||||
Log.d(TAG, "startForegroundIfPlaying: " + status);
|
||||
if (stateManager.hasReceivedValidStartCommand()) {
|
||||
if (isCasting || status == PlayerStatus.PLAYING || status == PlayerStatus.PREPARING
|
||||
|| status == PlayerStatus.SEEKING) {
|
||||
stateManager.startForeground(R.id.notification_playing, notificationBuilder.build());
|
||||
Log.d(TAG, "foreground");
|
||||
} else {
|
||||
stateManager.stopForeground(false);
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
|
||||
notificationManager.notify(R.id.notification_playing, notificationBuilder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists the current position and last played time of the media file.
|
||||
*
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package de.danoeh.antennapod.core.service.playback;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.app.ServiceCompat;
|
||||
|
||||
class PlaybackServiceStateManager {
|
||||
private static final String TAG = "PlaybackSrvState";
|
||||
private final PlaybackService playbackService;
|
||||
|
||||
private volatile boolean isInForeground = false;
|
||||
|
@ -15,17 +17,20 @@ class PlaybackServiceStateManager {
|
|||
}
|
||||
|
||||
void startForeground(int notificationId, Notification notification) {
|
||||
Log.d(TAG, "startForeground");
|
||||
playbackService.startForeground(notificationId, notification);
|
||||
isInForeground = true;
|
||||
}
|
||||
|
||||
void stopService() {
|
||||
Log.d(TAG, "stopService");
|
||||
stopForeground(true);
|
||||
playbackService.stopSelf();
|
||||
hasReceivedValidStartCommand = false;
|
||||
}
|
||||
|
||||
void stopForeground(boolean removeNotification) {
|
||||
Log.d(TAG, "stopForeground");
|
||||
if (isInForeground) {
|
||||
if (removeNotification) {
|
||||
ServiceCompat.stopForeground(playbackService, ServiceCompat.STOP_FOREGROUND_REMOVE);
|
||||
|
|
Loading…
Reference in New Issue