From 743ec1927c8abc2506b4a02264712313efc695b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Cabessa?= Date: Sun, 3 Mar 2019 18:28:43 +0100 Subject: add preference for "Time respects playback speed" --- app/src/main/res/xml/preferences_playback.xml | 5 +++++ .../java/de/danoeh/antennapod/core/preferences/UserPreferences.java | 5 +++++ core/src/main/res/values/strings.xml | 2 ++ 3 files changed, 12 insertions(+) diff --git a/app/src/main/res/xml/preferences_playback.xml b/app/src/main/res/xml/preferences_playback.xml index 9182df600..dad2f0ade 100644 --- a/app/src/main/res/xml/preferences_playback.xml +++ b/app/src/main/res/xml/preferences_playback.xml @@ -71,6 +71,11 @@ android:key="prefPlaybackSpeedLauncher" android:summary="@string/pref_playback_speed_sum" android:title="@string/pref_playback_speed_title"/> + diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index 805f0c1b6..c9a18e923 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -73,6 +73,7 @@ public class UserPreferences { private static final String PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS = "prefPauseForFocusLoss"; private static final String PREF_RESUME_AFTER_CALL = "prefResumeAfterCall"; public static final String PREF_VIDEO_BEHAVIOR = "prefVideoBehavior"; + private static final String PREF_TIME_RESPECTS_SPEED = "prefPlaybackTimeRespectsSpeed"; // Network private static final String PREF_ENQUEUE_DOWNLOADED = "prefEnqueueDownloaded"; @@ -871,4 +872,8 @@ public class UserPreferences { .putString(PREF_BACK_BUTTON_GO_TO_PAGE, tag) .apply(); } + + public static boolean timeRespectsSpeed() { + return prefs.getBoolean(PREF_TIME_RESPECTS_SPEED, false); + } } diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 665498c23..8dc3cfb99 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -472,6 +472,8 @@ This setting does not apply to authentication errors. Playback Speeds Customize the speeds available for variable speed audio playback + Adjust media info to playback speed + Displayed position and duration are adapted to playback speed Fast Forward Skip Time Customize the number of seconds to jump forward when the fast forward button is clicked Rewind Skip Time -- cgit v1.2.3 From 6187945e8f82dc36bdbc3a86e9723569107522d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Cabessa?= Date: Sun, 3 Mar 2019 18:35:52 +0100 Subject: add a time conversion class convert time depending on current playback speed and preferences --- .../antennapod/core/util/TimeSpeedConverter.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 core/src/main/java/de/danoeh/antennapod/core/util/TimeSpeedConverter.java diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/TimeSpeedConverter.java b/core/src/main/java/de/danoeh/antennapod/core/util/TimeSpeedConverter.java new file mode 100644 index 000000000..5fea8238b --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/util/TimeSpeedConverter.java @@ -0,0 +1,22 @@ +package de.danoeh.antennapod.core.util; + +import de.danoeh.antennapod.core.preferences.UserPreferences; + +public class TimeSpeedConverter { + private TimeSpeedConverter() { + + } + + /** Convert millisecond according to the current playback speed + * @param time: time to convert + * @return converted time (can be < 0 if time is < 0) + */ + public static int convert(int time) { + boolean timeRespectsSpeed = UserPreferences.timeRespectsSpeed(); + if (time > 0 && timeRespectsSpeed) { + float speed = Float.parseFloat(UserPreferences.getPlaybackSpeed()); + return (int)(time / speed); + } + return time; + } +} -- cgit v1.2.3 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: use time converter and pref in MediaPlayer and Widget --- .../antennapod/activity/MediaplayerActivity.java | 21 +++++++++++++++------ .../core/service/PlayerWidgetJobService.java | 3 +++ .../core/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; -- cgit v1.2.3 From b2dc2080193a44e732277f45db999da7f9ec98a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Cabessa?= Date: Sun, 3 Mar 2019 10:52:07 +0100 Subject: force refresh time when playback speed change This is useful when media is paused --- app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java index 67dda01cf..2bcd7a461 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -129,6 +129,7 @@ public class AudioplayerActivity extends MediaplayerInfoActivity { } UserPreferences.setPlaybackSpeed(newSpeed); controller.setPlaybackSpeed(Float.parseFloat(newSpeed)); + onPositionObserverUpdate(); } else { VariableSpeedDialog.showGetPluginDialog(this); } -- cgit v1.2.3 From 60771673dc4300f102da5e364d2980369742fef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Cabessa?= Date: Tue, 28 May 2019 12:03:28 +0200 Subject: rename category title to match with "playback speeds" also rename the key to be consistent with the content --- app/src/main/res/xml/preferences_playback.xml | 2 +- core/src/main/res/values/strings.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/xml/preferences_playback.xml b/app/src/main/res/xml/preferences_playback.xml index dad2f0ade..8b8efa023 100644 --- a/app/src/main/res/xml/preferences_playback.xml +++ b/app/src/main/res/xml/preferences_playback.xml @@ -46,7 +46,7 @@ app:useStockLayout="true"/> - + Appearance External elements Interruptions - Playback control buttons + Playback control Media player Episode Cleanup Episodes that aren\'t in the queue and aren\'t favorites should be eligible for removal if Auto Download needs space for new episodes -- cgit v1.2.3