Fix chapter seekbar issues (#5142)
Buffering indicator drawn incorrectly Not refreshing divider positions with duration change
This commit is contained in:
parent
3c808c1393
commit
508cea67d1
|
@ -98,6 +98,7 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
private boolean hasChapters = false;
|
||||
private boolean seekedToChapterStart = false;
|
||||
private int currentChapterIndex = -1;
|
||||
private int duration;
|
||||
private TabLayoutMediator tabLayoutMediator;
|
||||
|
||||
@Override
|
||||
|
@ -195,10 +196,9 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
if (hasChapters) {
|
||||
List<Chapter> chapters = media.getChapters();
|
||||
dividerPos = new float[chapters.size()];
|
||||
float duration = media.getDuration();
|
||||
|
||||
for (int i = 0; i < chapters.size(); i++) {
|
||||
dividerPos[i] = chapters.get(i).getStart() / duration;
|
||||
dividerPos[i] = chapters.get(i).getStart() / (float) duration;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -418,6 +418,8 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
return;
|
||||
}
|
||||
|
||||
duration = controller.getDuration();
|
||||
|
||||
if (media != null && media.getChapters() != null) {
|
||||
setHasChapters(media.getChapters().size() > 0);
|
||||
currentChapterIndex = ChapterUtils.getCurrentChapterIndex(media, controller.getPosition());
|
||||
|
@ -425,7 +427,7 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
setHasChapters(false);
|
||||
currentChapterIndex = -1;
|
||||
}
|
||||
updatePosition(new PlaybackPositionEvent(controller.getPosition(), controller.getDuration()));
|
||||
updatePosition(new PlaybackPositionEvent(controller.getPosition(), duration));
|
||||
updatePlaybackSpeedButton(media);
|
||||
setChapterDividers(media);
|
||||
setupOptionsMenu(media);
|
||||
|
@ -499,6 +501,7 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
if (controller == null || txtvLength == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fromUser) {
|
||||
float prog = progress / ((float) seekBar.getMax());
|
||||
TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier());
|
||||
|
@ -518,6 +521,8 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
} else {
|
||||
txtvSeek.setText(Converter.getDurationStringLong(position));
|
||||
}
|
||||
} else if (duration != controller.getDuration()) {
|
||||
updateUi(controller.getMedia());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -118,6 +118,14 @@ public class ChapterSeekBar extends androidx.appcompat.widget.AppCompatSeekBar {
|
|||
|
||||
canvas.drawRect(left, top, right, bottom, paintBackground);
|
||||
|
||||
if (progressSecondary > 0 && progressSecondary < width) {
|
||||
if (right < progressSecondary) {
|
||||
canvas.drawRect(left, top, right, bottom, paintBackground);
|
||||
} else if (progressSecondary > left) {
|
||||
canvas.drawRect(left, top, progressSecondary, bottom, paintBackground);
|
||||
}
|
||||
}
|
||||
|
||||
if (right < progressPrimary) {
|
||||
currChapter = i + 1;
|
||||
canvas.drawRect(left, top, right, bottom, paintProgressPrimary);
|
||||
|
@ -125,9 +133,6 @@ public class ChapterSeekBar extends androidx.appcompat.widget.AppCompatSeekBar {
|
|||
canvas.drawRect(leftCurr, topExpanded, rightCurr, bottomExpanded, paintBackground);
|
||||
canvas.drawRect(leftCurr, topExpanded, progressPrimary, bottomExpanded, paintProgressPrimary);
|
||||
} else {
|
||||
if (progressSecondary > leftCurr) {
|
||||
canvas.drawRect(leftCurr, top, progressSecondary, bottom, paintBackground);
|
||||
}
|
||||
canvas.drawRect(leftCurr, top, progressPrimary, bottom, paintProgressPrimary);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue