diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-05-28 15:52:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-28 15:52:54 +0200 |
commit | d81cb2ff398229024f71ca719ba2fbb708899fcb (patch) | |
tree | dbae988e2dc895b136fc1a3b9386702e145d2940 | |
parent | f563fe48b5dd49c8b9305b75ed8a598b83294739 (diff) | |
parent | 60771673dc4300f102da5e364d2980369742fef1 (diff) | |
download | AntennaPod-d81cb2ff398229024f71ca719ba2fbb708899fcb.zip |
Merge pull request #3043 from CedricCabessa/remaining_time_playback_speed
Fixes #2197: Remaining time playback speed
8 files changed, 58 insertions, 10 deletions
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); } 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 154c7c148..3d5c59a4a 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -55,6 +55,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; @@ -674,8 +675,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) { @@ -684,7 +688,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)); } @@ -832,9 +836,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); @@ -937,7 +945,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/app/src/main/res/xml/preferences_playback.xml b/app/src/main/res/xml/preferences_playback.xml index 9182df600..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"/> </PreferenceCategory> - <PreferenceCategory android:title="@string/buttons"> + <PreferenceCategory android:title="@string/playback_control"> <SwitchPreference android:defaultValue="false" android:enabled="true" @@ -71,6 +71,11 @@ android:key="prefPlaybackSpeedLauncher" android:summary="@string/pref_playback_speed_sum" android:title="@string/pref_playback_speed_title"/> + <SwitchPreference + android:defaultValue="false" + android:key="prefPlaybackTimeRespectsSpeed" + android:summary="@string/pref_playback_time_respects_speed_sum" + android:title="@string/pref_playback_time_respects_speed_title"/> </PreferenceCategory> <PreferenceCategory android:title="@string/queue_label"> 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/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/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; + } +} 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 2c70e9435..6191d4491 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 @@ -38,6 +38,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; @@ -566,8 +567,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; diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 99759374e..b11f47129 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -377,7 +377,7 @@ <string name="appearance">Appearance</string> <string name="external_elements">External elements</string> <string name="interruptions">Interruptions</string> - <string name="buttons">Playback control buttons</string> + <string name="playback_control">Playback control</string> <string name="media_player">Media player</string> <string name="pref_episode_cleanup_title">Episode Cleanup</string> <string name="pref_episode_cleanup_summary">Episodes that aren\'t in the queue and aren\'t favorites should be eligible for removal if Auto Download needs space for new episodes</string> @@ -474,6 +474,8 @@ <string name="pref_gpodnet_notifications_sum">This setting does not apply to authentication errors.</string> <string name="pref_playback_speed_title">Playback Speeds</string> <string name="pref_playback_speed_sum">Customize the speeds available for variable speed audio playback</string> + <string name="pref_playback_time_respects_speed_title">Adjust media info to playback speed</string> + <string name="pref_playback_time_respects_speed_sum">Displayed position and duration are adapted to playback speed</string> <string name="pref_fast_forward">Fast Forward Skip Time</string> <string name="pref_fast_forward_sum">Customize the number of seconds to jump forward when the fast forward button is clicked</string> <string name="pref_rewind">Rewind Skip Time</string> |