Skip to content

Commit

Permalink
fix progress time calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-fichtner authored and nielsvanvelzen committed Feb 26, 2025
1 parent f855c1a commit 2a49b8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ private void updateDisplay(BaseItemDto program) {
.append(DateTimeExtensionsKt.getTimeFormatter(getContext()).format(program.getEndDate()))
);

if (program.getStartDate().isAfter(LocalDateTime.now()) && program.getEndDate().isBefore(LocalDateTime.now())) {
if (program.getStartDate().isBefore(LocalDateTime.now()) && program.getEndDate().isAfter(LocalDateTime.now())) {
Duration duration = Duration.between(program.getStartDate(), program.getEndDate());
Duration progress = Duration.between(program.getStartDate(), LocalDateTime.now());

binding.progress.setProgress((int) (progress.getSeconds() / duration.getSeconds() * 100));
binding.progress.setProgress((int) ((progress.getSeconds() / (double) duration.getSeconds()) * 100));
} else {
binding.progress.setProgress(0);
}
}
} else {
binding.time.setText("");
binding.progress.setProgress(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import kotlin.Lazy;
import timber.log.Timber;

import java.time.Duration;

public class PlaybackController implements PlaybackControllerNotifiable {
// Frequency to report playback progress
private final static long PROGRESS_REPORTING_INTERVAL = TimeUtils.secondsToMillis(3);
Expand Down Expand Up @@ -978,7 +980,7 @@ public void updateTvProgramInfo() {
BaseItemDto program = updatedChannel.getCurrentProgram();
if (program != null) {
mCurrentProgramEnd = program.getEndDate();
mCurrentProgramStart = program.getPremiereDate();
mCurrentProgramStart = program.getStartDate();
if (mFragment != null) mFragment.updateDisplay();
}
return null;
Expand All @@ -987,11 +989,10 @@ public void updateTvProgramInfo() {
}

private long getRealTimeProgress() {
long progress = Instant.now().toEpochMilli();
if (mCurrentProgramStart != null) {
progress -= mCurrentProgramStart.toInstant(ZoneOffset.UTC).toEpochMilli();
return Duration.between(mCurrentProgramStart, LocalDateTime.now()).toMillis();
}
return progress;
return 0;
}

private long getTimeShiftedProgress() {
Expand Down

0 comments on commit 2a49b8b

Please sign in to comment.