From cf638a497813741757e2d9fd6f77bb171ed85c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Cabessa?= Date: Sat, 2 Mar 2019 16:22:05 +0100 Subject: [PATCH] use time converter and pref in MediaPlayer and Widget --- .../activity/MediaplayerActivity.java | 21 +++++++++++++------ .../core/service/PlayerWidgetJobService.java | 3 +++ .../util/playback/PlaybackController.java | 5 +++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index 86d4ec642..781d059f6 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -56,6 +56,7 @@ import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.core.util.Supplier; +import de.danoeh.antennapod.core.util.TimeSpeedConverter; import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil; import de.danoeh.antennapod.core.util.playback.ExternalMedia; import de.danoeh.antennapod.core.util.playback.MediaPlayerError; @@ -684,8 +685,11 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements if (controller == null || txtvPosition == null || txtvLength == null) { return; } - int currentPosition = controller.getPosition(); - int duration = controller.getDuration(); + + int currentPosition = TimeSpeedConverter.convert(controller.getPosition()); + int duration = TimeSpeedConverter.convert(controller.getDuration()); + int remainingTime = TimeSpeedConverter.convert( + controller.getDuration() - controller.getPosition()); Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition)); if (currentPosition == PlaybackService.INVALID_TIME || duration == PlaybackService.INVALID_TIME) { @@ -694,7 +698,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements } txtvPosition.setText(Converter.getDurationStringLong(currentPosition)); if (showTimeLeft) { - txtvLength.setText("-" + Converter.getDurationStringLong(duration - currentPosition)); + txtvLength.setText("-" + Converter.getDurationStringLong(remainingTime)); } else { txtvLength.setText(Converter.getDurationStringLong(duration)); } @@ -842,9 +846,13 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements String length; if (showTimeLeft) { - length = "-" + Converter.getDurationStringLong(media.getDuration() - media.getPosition()); + int remainingTime = TimeSpeedConverter.convert( + media.getDuration() - media.getPosition()); + + length = "-" + Converter.getDurationStringLong(remainingTime); } else { - length = Converter.getDurationStringLong(media.getDuration()); + int duration = TimeSpeedConverter.convert(media.getDuration()); + length = Converter.getDurationStringLong(duration); } txtvLength.setText(length); @@ -947,7 +955,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements prog = controller.onSeekBarProgressChanged(seekBar, progress, fromUser, txtvPosition); if (showTimeLeft && prog != 0) { int duration = controller.getDuration(); - String length = "-" + Converter.getDurationStringLong(duration - (int) (prog * duration)); + int timeLeft = TimeSpeedConverter.convert(duration - (int) (prog * duration)); + String length = "-" + Converter.getDurationStringLong(timeLeft); txtvLength.setText(length); } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java b/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java index 6dab9a561..773a1f6e1 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java @@ -21,6 +21,7 @@ import de.danoeh.antennapod.core.receiver.PlayerWidget; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlayerStatus; import de.danoeh.antennapod.core.util.Converter; +import de.danoeh.antennapod.core.util.TimeSpeedConverter; import de.danoeh.antennapod.core.util.playback.Playable; /** @@ -152,6 +153,8 @@ public class PlayerWidgetJobService extends SafeJobIntentService { private String getProgressString(int position, int duration) { if (position > 0 && duration > 0) { + position = TimeSpeedConverter.convert(position); + duration = TimeSpeedConverter.convert(duration); return Converter.getDurationStringLong(position) + " / " + Converter.getDurationStringLong(duration); } else { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java index 4d5ed449b..efadfdcb8 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java @@ -36,6 +36,7 @@ import de.danoeh.antennapod.core.service.playback.PlayerStatus; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.Optional; +import de.danoeh.antennapod.core.util.TimeSpeedConverter; import de.danoeh.antennapod.core.util.playback.Playable.PlayableUtils; import io.reactivex.Maybe; import io.reactivex.MaybeOnSubscribe; @@ -540,8 +541,8 @@ public abstract class PlaybackController { if (fromUser && playbackService != null && media != null) { float prog = progress / ((float) seekBar.getMax()); int duration = media.getDuration(); - txtvPosition.setText(Converter - .getDurationStringLong((int) (prog * duration))); + int position = TimeSpeedConverter.convert((int) (prog * duration)); + txtvPosition.setText(Converter.getDurationStringLong(position)); return prog; } return 0;