use time converter and pref in MediaPlayer and Widget

This commit is contained in:
Cédric Cabessa 2019-03-02 16:22:05 +01:00
parent 6187945e8f
commit cf638a4978
3 changed files with 21 additions and 8 deletions

View File

@ -56,6 +56,7 @@ import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.ShareUtils;
import de.danoeh.antennapod.core.util.StorageUtils; import de.danoeh.antennapod.core.util.StorageUtils;
import de.danoeh.antennapod.core.util.Supplier; 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.gui.PictureInPictureUtil;
import de.danoeh.antennapod.core.util.playback.ExternalMedia; import de.danoeh.antennapod.core.util.playback.ExternalMedia;
import de.danoeh.antennapod.core.util.playback.MediaPlayerError; 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) { if (controller == null || txtvPosition == null || txtvLength == null) {
return; 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)); Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition));
if (currentPosition == PlaybackService.INVALID_TIME || if (currentPosition == PlaybackService.INVALID_TIME ||
duration == PlaybackService.INVALID_TIME) { duration == PlaybackService.INVALID_TIME) {
@ -694,7 +698,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
} }
txtvPosition.setText(Converter.getDurationStringLong(currentPosition)); txtvPosition.setText(Converter.getDurationStringLong(currentPosition));
if (showTimeLeft) { if (showTimeLeft) {
txtvLength.setText("-" + Converter.getDurationStringLong(duration - currentPosition)); txtvLength.setText("-" + Converter.getDurationStringLong(remainingTime));
} else { } else {
txtvLength.setText(Converter.getDurationStringLong(duration)); txtvLength.setText(Converter.getDurationStringLong(duration));
} }
@ -842,9 +846,13 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
String length; String length;
if (showTimeLeft) { if (showTimeLeft) {
length = "-" + Converter.getDurationStringLong(media.getDuration() - media.getPosition()); int remainingTime = TimeSpeedConverter.convert(
media.getDuration() - media.getPosition());
length = "-" + Converter.getDurationStringLong(remainingTime);
} else { } else {
length = Converter.getDurationStringLong(media.getDuration()); int duration = TimeSpeedConverter.convert(media.getDuration());
length = Converter.getDurationStringLong(duration);
} }
txtvLength.setText(length); txtvLength.setText(length);
@ -947,7 +955,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
prog = controller.onSeekBarProgressChanged(seekBar, progress, fromUser, txtvPosition); prog = controller.onSeekBarProgressChanged(seekBar, progress, fromUser, txtvPosition);
if (showTimeLeft && prog != 0) { if (showTimeLeft && prog != 0) {
int duration = controller.getDuration(); 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); txtvLength.setText(length);
} }
} }

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.PlaybackService;
import de.danoeh.antennapod.core.service.playback.PlayerStatus; import de.danoeh.antennapod.core.service.playback.PlayerStatus;
import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.TimeSpeedConverter;
import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.Playable;
/** /**
@ -152,6 +153,8 @@ public class PlayerWidgetJobService extends SafeJobIntentService {
private String getProgressString(int position, int duration) { private String getProgressString(int position, int duration) {
if (position > 0 && duration > 0) { if (position > 0 && duration > 0) {
position = TimeSpeedConverter.convert(position);
duration = TimeSpeedConverter.convert(duration);
return Converter.getDurationStringLong(position) + " / " return Converter.getDurationStringLong(position) + " / "
+ Converter.getDurationStringLong(duration); + Converter.getDurationStringLong(duration);
} else { } else {

View File

@ -36,6 +36,7 @@ import de.danoeh.antennapod.core.service.playback.PlayerStatus;
import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.Optional; import de.danoeh.antennapod.core.util.Optional;
import de.danoeh.antennapod.core.util.TimeSpeedConverter;
import de.danoeh.antennapod.core.util.playback.Playable.PlayableUtils; import de.danoeh.antennapod.core.util.playback.Playable.PlayableUtils;
import io.reactivex.Maybe; import io.reactivex.Maybe;
import io.reactivex.MaybeOnSubscribe; import io.reactivex.MaybeOnSubscribe;
@ -540,8 +541,8 @@ public abstract class PlaybackController {
if (fromUser && playbackService != null && media != null) { if (fromUser && playbackService != null && media != null) {
float prog = progress / ((float) seekBar.getMax()); float prog = progress / ((float) seekBar.getMax());
int duration = media.getDuration(); int duration = media.getDuration();
txtvPosition.setText(Converter int position = TimeSpeedConverter.convert((int) (prog * duration));
.getDurationStringLong((int) (prog * duration))); txtvPosition.setText(Converter.getDurationStringLong(position));
return prog; return prog;
} }
return 0; return 0;