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