Fix playback position not saved after being changed, when episode is paused (#7911)

This commit is contained in:
Mino 2025-08-04 07:39:00 +01:00 committed by GitHub
parent 448e1c1b8b
commit cfd9e1f886
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 17 additions and 11 deletions

View File

@ -256,8 +256,8 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder {
return item;
}
public boolean isCurrentlyPlayingItem() {
return item.getMedia() != null && PlaybackStatus.isCurrentlyPlaying(item.getMedia());
public boolean isPlayingItem() {
return item.getMedia() != null && PlaybackStatus.isPlaying(item.getMedia());
}
public void notifyPlaybackPositionUpdated(PlaybackPositionEvent event) {

View File

@ -347,7 +347,7 @@ public abstract class EpisodesListFragment extends Fragment
public void onEventMainThread(PlaybackPositionEvent event) {
for (int i = 0; i < listAdapter.getItemCount(); i++) {
EpisodeItemViewHolder holder = (EpisodeItemViewHolder) recyclerView.findViewHolderForAdapterPosition(i);
if (holder != null && holder.isCurrentlyPlayingItem()) {
if (holder != null && holder.isPlayingItem()) {
holder.notifyPlaybackPositionUpdated(event);
break;
}

View File

@ -358,7 +358,7 @@ public class SearchFragment extends Fragment implements EpisodeItemListAdapter.O
if (adapter != null) {
for (int i = 0; i < adapter.getItemCount(); i++) {
EpisodeItemViewHolder holder = (EpisodeItemViewHolder) recyclerView.findViewHolderForAdapterPosition(i);
if (holder != null && holder.isCurrentlyPlayingItem()) {
if (holder != null && holder.isPlayingItem()) {
holder.notifyPlaybackPositionUpdated(event);
break;
}

View File

@ -277,7 +277,7 @@ public class CompletedDownloadsFragment extends Fragment
if (adapter != null) {
for (int i = 0; i < adapter.getItemCount(); i++) {
EpisodeItemViewHolder holder = (EpisodeItemViewHolder) recyclerView.findViewHolderForAdapterPosition(i);
if (holder != null && holder.isCurrentlyPlayingItem()) {
if (holder != null && holder.isPlayingItem()) {
holder.notifyPlaybackPositionUpdated(event);
break;
}

View File

@ -424,7 +424,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
for (int i = 0; i < adapter.getItemCount(); i++) {
EpisodeItemViewHolder holder = (EpisodeItemViewHolder)
viewBinding.recyclerView.findViewHolderForAdapterPosition(i);
if (holder != null && holder.isCurrentlyPlayingItem()) {
if (holder != null && holder.isPlayingItem()) {
holder.notifyPlaybackPositionUpdated(event);
break;
}

View File

@ -96,7 +96,7 @@ public class DownloadsSection extends HomeSection {
for (int i = 0; i < adapter.getItemCount(); i++) {
EpisodeItemViewHolder holder = (EpisodeItemViewHolder)
viewBinding.recyclerView.findViewHolderForAdapterPosition(i);
if (holder != null && holder.isCurrentlyPlayingItem()) {
if (holder != null && holder.isPlayingItem()) {
holder.notifyPlaybackPositionUpdated(event);
break;
}

View File

@ -217,7 +217,7 @@ public class QueueFragment extends Fragment implements MaterialToolbar.OnMenuIte
for (int i = 0; i < recyclerAdapter.getItemCount(); i++) {
EpisodeItemViewHolder holder = (EpisodeItemViewHolder)
recyclerView.findViewHolderForAdapterPosition(i);
if (holder != null && holder.isCurrentlyPlayingItem()) {
if (holder != null && holder.isPlayingItem()) {
holder.notifyPlaybackPositionUpdated(event);
break;
}

View File

@ -13,6 +13,7 @@ import android.util.Pair;
import android.view.SurfaceHolder;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import de.danoeh.antennapod.playback.service.internal.PlayableUtils;
import de.danoeh.antennapod.storage.database.DBReader;
import de.danoeh.antennapod.storage.database.DBWriter;
import de.danoeh.antennapod.event.playback.PlaybackPositionEvent;
@ -376,13 +377,18 @@ public abstract class PlaybackController {
}
public void seekTo(int time) {
Playable playable = getMedia();
if (playbackService != null) {
if (playable != null) {
long timestamp = playable.getLastPlayedTimeStatistics();
PlayableUtils.saveCurrentPosition(playable, time, timestamp);
}
playbackService.seekTo(time);
} else if (getMedia() instanceof FeedMedia) {
FeedMedia media = (FeedMedia) getMedia();
} else if (playable instanceof FeedMedia) {
FeedMedia media = (FeedMedia) playable;
media.setPosition(time);
DBWriter.setFeedItem(media.getItem());
EventBus.getDefault().post(new PlaybackPositionEvent(time, getMedia().getDuration()));
EventBus.getDefault().post(new PlaybackPositionEvent(time, playable.getDuration()));
}
}