From e4bac5ea71d8dc9b3cc8608b85cb461a6097e40f Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sat, 6 Apr 2024 20:24:47 +0200 Subject: [PATCH] Do not crash if an event comes in before the media is loaded (#7067) --- .../danoeh/antennapod/ui/screen/chapter/ChaptersFragment.java | 2 +- .../antennapod/ui/screen/playback/audio/CoverFragment.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/danoeh/antennapod/ui/screen/chapter/ChaptersFragment.java b/app/src/main/java/de/danoeh/antennapod/ui/screen/chapter/ChaptersFragment.java index 8fea6e209..45838d845 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/screen/chapter/ChaptersFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/screen/chapter/ChaptersFragment.java @@ -127,7 +127,7 @@ public class ChaptersFragment extends AppCompatDialogFragment { } private int getCurrentChapter(Playable media) { - if (controller == null) { + if (controller == null || media == null) { return -1; } return Chapter.getAfterPosition(media.getChapters(), controller.getPosition()); diff --git a/app/src/main/java/de/danoeh/antennapod/ui/screen/playback/audio/CoverFragment.java b/app/src/main/java/de/danoeh/antennapod/ui/screen/playback/audio/CoverFragment.java index 57794b410..073d5b0be 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/screen/playback/audio/CoverFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/screen/playback/audio/CoverFragment.java @@ -261,6 +261,9 @@ public class CoverFragment extends Fragment { @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(PlaybackPositionEvent event) { + if (media == null) { + return; + } int newChapterIndex = Chapter.getAfterPosition(media.getChapters(), event.getPosition()); if (newChapterIndex > -1 && newChapterIndex != displayedChapterIndex) { refreshChapterData(newChapterIndex);