Merge pull request #5546 from ByteHamster/incorrect-position

Fix sometimes showing incorrect position when continuous playback is disabled
This commit is contained in:
ByteHamster 2021-11-14 16:40:55 +01:00 committed by GitHub
commit 51e44c68c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 22 deletions

View File

@ -299,11 +299,11 @@ public class AudioPlayerFragment extends Fragment implements
}
private void updateUi(Playable media) {
if (controller == null) {
if (controller == null || media == null) {
return;
}
duration = controller.getDuration();
updatePosition(new PlaybackPositionEvent(controller.getPosition(), duration));
updatePosition(new PlaybackPositionEvent(media.getPosition(), media.getDuration()));
updatePlaybackSpeedButton(new SpeedChangedEvent(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media)));
setChapterDividers(media);
setupOptionsMenu(media);

View File

@ -99,12 +99,6 @@ public class ExternalPlayerFragment extends Fragment {
private PlaybackController setupPlaybackController() {
return new PlaybackController(getActivity()) {
@Override
public void onPositionObserverUpdate() {
ExternalPlayerFragment.this.onPositionObserverUpdate();
}
@Override
protected void updatePlayButtonShowsPlay(boolean showPlay) {
butPlay.setIsShowPlay(showPlay);
@ -142,8 +136,15 @@ public class ExternalPlayerFragment extends Fragment {
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(PlaybackPositionEvent event) {
onPositionObserverUpdate();
public void onPositionObserverUpdate(PlaybackPositionEvent event) {
if (controller == null) {
return;
} else if (controller.getPosition() == PlaybackService.INVALID_TIME
|| controller.getDuration() == PlaybackService.INVALID_TIME) {
return;
}
progressBar.setProgress((int)
((double) controller.getPosition() / controller.getDuration() * 100));
}
@Subscribe(threadMode = ThreadMode.MAIN)
@ -195,7 +196,7 @@ public class ExternalPlayerFragment extends Fragment {
((MainActivity) getActivity()).setPlayerVisible(true);
txtvTitle.setText(media.getEpisodeTitle());
feedName.setText(media.getFeedTitle());
onPositionObserverUpdate();
onPositionObserverUpdate(new PlaybackPositionEvent(media.getPosition(), media.getDuration()));
RequestOptions options = new RequestOptions()
.placeholder(R.color.light_gray)
@ -220,15 +221,4 @@ public class ExternalPlayerFragment extends Fragment {
((MainActivity) getActivity()).getBottomSheet().setLocked(false);
}
}
private void onPositionObserverUpdate() {
if (controller == null) {
return;
} else if (controller.getPosition() == PlaybackService.INVALID_TIME
|| controller.getDuration() == PlaybackService.INVALID_TIME) {
return;
}
progressBar.setProgress((int)
((double) controller.getPosition() / controller.getDuration() * 100));
}
}