Do not crash if an event comes in before the media is loaded (#7067)

This commit is contained in:
ByteHamster 2024-04-06 20:24:47 +02:00 committed by GitHub
parent 00d6df6261
commit e4bac5ea71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -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());

View File

@ -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);