summaryrefslogtreecommitdiff
path: root/playback
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2024-04-15 19:23:26 +0200
committerGitHub <noreply@github.com>2024-04-15 19:23:26 +0200
commit91bcf4b4009603944378d3dc5e6ee0628e5b80b9 (patch)
tree5a01afeaf395bae58153728e39e7f7714a05dbba /playback
parent8037bd2239496495a03a06dda1307627ffc3c18b (diff)
downloadAntennaPod-91bcf4b4009603944378d3dc5e6ee0628e5b80b9.zip
Work around race condition where position reset might be undone (#7102)
When the position saver ticks while the service is just about to be stopped, it might happen that we first reset the position and then set it to the end again. This works around this.
Diffstat (limited to 'playback')
-rw-r--r--playback/service/src/main/java/de/danoeh/antennapod/playback/service/PlaybackService.java17
1 files changed, 11 insertions, 6 deletions
diff --git a/playback/service/src/main/java/de/danoeh/antennapod/playback/service/PlaybackService.java b/playback/service/src/main/java/de/danoeh/antennapod/playback/service/PlaybackService.java
index 7f213a598..02a6c9500 100644
--- a/playback/service/src/main/java/de/danoeh/antennapod/playback/service/PlaybackService.java
+++ b/playback/service/src/main/java/de/danoeh/antennapod/playback/service/PlaybackService.java
@@ -162,6 +162,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
private CastStateListener castStateListener;
private String autoSkippedFeedMediaId = null;
+ private String positionJustResetAfterPlayback = null;
private int clickCount = 0;
private final Handler clickHandler = new Handler(Looper.getMainLooper());
@@ -874,6 +875,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
(ctx) -> disableSleepTimer(), getString(R.string.undo)));
}
loadQueueForMediaSession();
+ positionJustResetAfterPlayback = null;
break;
case ERROR:
PlaybackPreferences.writeNoMediaPlaying();
@@ -935,15 +937,17 @@ public class PlaybackService extends MediaBrowserServiceCompat {
public void onPlaybackPause(Playable playable, int position) {
taskManager.cancelPositionSaver();
cancelPositionObserver();
- saveCurrentPosition(position == Playable.INVALID_TIME || playable == null, playable, position);
taskManager.cancelWidgetUpdater();
- if (playable != null) {
- if (playable instanceof FeedMedia) {
- SynchronizationQueueSink.enqueueEpisodePlayedIfSynchronizationIsActive(getApplicationContext(),
- (FeedMedia) playable, false);
+ if (playable instanceof FeedMedia) {
+ FeedMedia media = (FeedMedia) playable;
+ if (!media.getItem().getIdentifyingValue().equals(positionJustResetAfterPlayback)) {
+ // Don't store position after position is already reset
+ saveCurrentPosition(position == Playable.INVALID_TIME, playable, position);
}
- playable.onPlaybackPause(getApplicationContext());
+ SynchronizationQueueSink.enqueueEpisodePlayedIfSynchronizationIsActive(getApplicationContext(),
+ media, false);
}
+ playable.onPlaybackPause(getApplicationContext());
}
@Override
@@ -1152,6 +1156,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|| autoSkipped
|| (skipped && !UserPreferences.shouldSkipKeepEpisode())) {
// only mark the item as played if we're not keeping it anyways
+ positionJustResetAfterPlayback = item.getIdentifyingValue();
DBWriter.markItemPlayed(item, FeedItem.PLAYED, ended || (skipped && almostEnded));
// don't know if it actually matters to not autodownload when smart mark as played is triggered
DBWriter.removeQueueItem(PlaybackService.this, ended, item);