Merge pull request #3043 from CedricCabessa/remaining_time_playback_speed

Fixes #2197: Remaining time playback speed
This commit is contained in:
H. Lehmann 2019-05-28 15:52:54 +02:00 committed by GitHub
commit d81cb2ff39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 10 deletions

View File

@ -129,6 +129,7 @@ public class AudioplayerActivity extends MediaplayerInfoActivity {
}
UserPreferences.setPlaybackSpeed(newSpeed);
controller.setPlaybackSpeed(Float.parseFloat(newSpeed));
onPositionObserverUpdate();
} else {
VariableSpeedDialog.showGetPluginDialog(this);
}

View File

@ -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);
}
}

View File

@ -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">

View File

@ -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);
}
}

View File

@ -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 {

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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>