Merge pull request #3343 from ByteHamster/video-playback-speed
Allow to adjust video playback speed
This commit is contained in:
commit
9ae179adce
|
@ -76,14 +76,7 @@ public class AudioplayerActivity extends MediaplayerInfoActivity {
|
|||
}
|
||||
float speed = 1.0f;
|
||||
if(controller.canSetPlaybackSpeed()) {
|
||||
try {
|
||||
// we can only retrieve the playback speed from the controller/playback service
|
||||
// once mediaplayer has been initialized
|
||||
speed = Float.parseFloat(UserPreferences.getPlaybackSpeed());
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, Log.getStackTraceString(e));
|
||||
UserPreferences.setPlaybackSpeed(String.valueOf(speed));
|
||||
}
|
||||
speed = UserPreferences.getPlaybackSpeed();
|
||||
}
|
||||
String speedStr = new DecimalFormat("0.00x").format(speed);
|
||||
butPlaybackSpeed.setText(speedStr);
|
||||
|
@ -105,7 +98,7 @@ public class AudioplayerActivity extends MediaplayerInfoActivity {
|
|||
}
|
||||
if (controller.canSetPlaybackSpeed()) {
|
||||
String[] availableSpeeds = UserPreferences.getPlaybackSpeedArray();
|
||||
String currentSpeed = UserPreferences.getPlaybackSpeed();
|
||||
String currentSpeed = new DecimalFormat("0.00x").format(UserPreferences.getPlaybackSpeed());
|
||||
|
||||
// Provide initial value in case the speed list has changed
|
||||
// out from under us
|
||||
|
|
|
@ -22,8 +22,6 @@ import android.view.Menu;
|
|||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
|
@ -35,8 +33,6 @@ import com.bumptech.glide.Glide;
|
|||
import com.joanzapata.iconify.IconDrawable;
|
||||
import com.joanzapata.iconify.fonts.FontAwesomeIcons;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
|
@ -44,7 +40,6 @@ import de.danoeh.antennapod.core.feed.MediaType;
|
|||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.core.util.Consumer;
|
||||
import de.danoeh.antennapod.core.util.Converter;
|
||||
|
@ -62,8 +57,8 @@ import de.danoeh.antennapod.core.util.playback.MediaPlayerError;
|
|||
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
|
||||
import de.danoeh.antennapod.dialog.PlaybackControlsDialog;
|
||||
import de.danoeh.antennapod.dialog.SleepTimerDialog;
|
||||
import de.danoeh.antennapod.dialog.VariableSpeedDialog;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
@ -79,9 +74,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
private static final String PREFS = "MediaPlayerActivityPreferences";
|
||||
private static final String PREF_SHOW_TIME_LEFT = "showTimeLeft";
|
||||
private static final int REQUEST_CODE_STORAGE = 42;
|
||||
private static final float PLAYBACK_SPEED_STEP = 0.05f;
|
||||
private static final float DEFAULT_MIN_PLAYBACK_SPEED = 0.5f;
|
||||
private static final float DEFAULT_MAX_PLAYBACK_SPEED = 2.5f;
|
||||
|
||||
PlaybackController controller;
|
||||
|
||||
|
@ -365,7 +357,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
menu.findItem(R.id.audio_controls).setIcon(new IconDrawable(this,
|
||||
FontAwesomeIcons.fa_sliders).color(textColor).actionBarSize());
|
||||
} else {
|
||||
menu.findItem(R.id.audio_controls).setVisible(false);
|
||||
menu.findItem(R.id.audio_controls).setIcon(new IconDrawable(this,
|
||||
FontAwesomeIcons.fa_sliders).color(0xffffffff).actionBarSize());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -451,148 +444,9 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
}
|
||||
break;
|
||||
case R.id.audio_controls:
|
||||
MaterialDialog dialog = new MaterialDialog.Builder(this)
|
||||
.title(R.string.audio_controls)
|
||||
.customView(R.layout.audio_controls, true)
|
||||
.neutralText(R.string.close_label)
|
||||
.onNeutral((dialog1, which) -> {
|
||||
final SeekBar left = (SeekBar) dialog1.findViewById(R.id.volume_left);
|
||||
final SeekBar right = (SeekBar) dialog1.findViewById(R.id.volume_right);
|
||||
UserPreferences.setVolume(left.getProgress(), right.getProgress());
|
||||
})
|
||||
.show();
|
||||
final SeekBar barPlaybackSpeed = (SeekBar) dialog.findViewById(R.id.playback_speed);
|
||||
final Button butDecSpeed = (Button) dialog.findViewById(R.id.butDecSpeed);
|
||||
butDecSpeed.setOnClickListener(v -> {
|
||||
if(controller != null && controller.canSetPlaybackSpeed()) {
|
||||
barPlaybackSpeed.setProgress(barPlaybackSpeed.getProgress() - 1);
|
||||
} else {
|
||||
VariableSpeedDialog.showGetPluginDialog(this);
|
||||
}
|
||||
});
|
||||
final Button butIncSpeed = (Button) dialog.findViewById(R.id.butIncSpeed);
|
||||
butIncSpeed.setOnClickListener(v -> {
|
||||
if(controller != null && controller.canSetPlaybackSpeed()) {
|
||||
barPlaybackSpeed.setProgress(barPlaybackSpeed.getProgress() + 1);
|
||||
} else {
|
||||
VariableSpeedDialog.showGetPluginDialog(this);
|
||||
}
|
||||
});
|
||||
|
||||
final TextView txtvPlaybackSpeed = (TextView) dialog.findViewById(R.id.txtvPlaybackSpeed);
|
||||
float currentSpeed = 1.0f;
|
||||
try {
|
||||
currentSpeed = Float.parseFloat(UserPreferences.getPlaybackSpeed());
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, Log.getStackTraceString(e));
|
||||
UserPreferences.setPlaybackSpeed(String.valueOf(currentSpeed));
|
||||
}
|
||||
|
||||
String[] availableSpeeds = UserPreferences.getPlaybackSpeedArray();
|
||||
final float minPlaybackSpeed = availableSpeeds.length > 1 ?
|
||||
Float.valueOf(availableSpeeds[0]) : DEFAULT_MIN_PLAYBACK_SPEED;
|
||||
float maxPlaybackSpeed = availableSpeeds.length > 1 ?
|
||||
Float.valueOf(availableSpeeds[availableSpeeds.length - 1]) : DEFAULT_MAX_PLAYBACK_SPEED;
|
||||
int progressMax = (int) ((maxPlaybackSpeed - minPlaybackSpeed) / PLAYBACK_SPEED_STEP);
|
||||
barPlaybackSpeed.setMax(progressMax);
|
||||
|
||||
txtvPlaybackSpeed.setText(String.format("%.2fx", currentSpeed));
|
||||
barPlaybackSpeed.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if(controller != null && controller.canSetPlaybackSpeed()) {
|
||||
float playbackSpeed = progress * PLAYBACK_SPEED_STEP + minPlaybackSpeed;
|
||||
controller.setPlaybackSpeed(playbackSpeed);
|
||||
String speedPref = String.format(Locale.US, "%.2f", playbackSpeed);
|
||||
UserPreferences.setPlaybackSpeed(speedPref);
|
||||
String speedStr = String.format("%.2fx", playbackSpeed);
|
||||
txtvPlaybackSpeed.setText(speedStr);
|
||||
} else if(fromUser) {
|
||||
float speed = Float.valueOf(UserPreferences.getPlaybackSpeed());
|
||||
barPlaybackSpeed.post(() -> barPlaybackSpeed.setProgress(
|
||||
(int) ((speed - minPlaybackSpeed) / PLAYBACK_SPEED_STEP)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
if(controller != null && !controller.canSetPlaybackSpeed()) {
|
||||
VariableSpeedDialog.showGetPluginDialog(MediaplayerActivity.this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
});
|
||||
barPlaybackSpeed.setProgress((int) ((currentSpeed - minPlaybackSpeed) / PLAYBACK_SPEED_STEP));
|
||||
|
||||
final SeekBar barLeftVolume = (SeekBar) dialog.findViewById(R.id.volume_left);
|
||||
barLeftVolume.setProgress(UserPreferences.getLeftVolumePercentage());
|
||||
final SeekBar barRightVolume = (SeekBar) dialog.findViewById(R.id.volume_right);
|
||||
barRightVolume.setProgress(UserPreferences.getRightVolumePercentage());
|
||||
final CheckBox stereoToMono = (CheckBox) dialog.findViewById(R.id.stereo_to_mono);
|
||||
stereoToMono.setChecked(UserPreferences.stereoToMono());
|
||||
if (controller != null && !controller.canDownmix()) {
|
||||
stereoToMono.setEnabled(false);
|
||||
String sonicOnly = getString(R.string.sonic_only);
|
||||
stereoToMono.setText(stereoToMono.getText() + " [" + sonicOnly + "]");
|
||||
}
|
||||
|
||||
if (UserPreferences.useExoplayer()) {
|
||||
barRightVolume.setEnabled(false);
|
||||
}
|
||||
|
||||
final CheckBox skipSilence = (CheckBox) dialog.findViewById(R.id.skipSilence);
|
||||
skipSilence.setChecked(UserPreferences.isSkipSilence());
|
||||
if (!UserPreferences.useExoplayer()) {
|
||||
skipSilence.setEnabled(false);
|
||||
String exoplayerOnly = getString(R.string.exoplayer_only);
|
||||
skipSilence.setText(skipSilence.getText() + " [" + exoplayerOnly + "]");
|
||||
}
|
||||
skipSilence.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
UserPreferences.setSkipSilence(isChecked);
|
||||
controller.setSkipSilence(isChecked);
|
||||
});
|
||||
|
||||
barLeftVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
controller.setVolume(
|
||||
Converter.getVolumeFromPercentage(progress),
|
||||
Converter.getVolumeFromPercentage(barRightVolume.getProgress()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
});
|
||||
barRightVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
controller.setVolume(
|
||||
Converter.getVolumeFromPercentage(barLeftVolume.getProgress()),
|
||||
Converter.getVolumeFromPercentage(progress));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
});
|
||||
stereoToMono.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
UserPreferences.stereoToMono(isChecked);
|
||||
if (controller != null) {
|
||||
controller.setDownmix(isChecked);
|
||||
}
|
||||
});
|
||||
boolean isPlayingVideo = controller.getMedia().getMediaType() == MediaType.VIDEO;
|
||||
PlaybackControlsDialog dialog = PlaybackControlsDialog.newInstance(isPlayingVideo);
|
||||
dialog.show(getSupportFragmentManager(), "playback_controls");
|
||||
break;
|
||||
case R.id.visit_website_item:
|
||||
Uri uri = Uri.parse(getWebsiteLinkWithFallback(media));
|
||||
|
@ -666,9 +520,10 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
return;
|
||||
}
|
||||
|
||||
int currentPosition = TimeSpeedConverter.convert(controller.getPosition());
|
||||
int duration = TimeSpeedConverter.convert(controller.getDuration());
|
||||
int remainingTime = TimeSpeedConverter.convert(
|
||||
TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier());
|
||||
int currentPosition = converter.convert(controller.getPosition());
|
||||
int duration = converter.convert(controller.getDuration());
|
||||
int remainingTime = converter.convert(
|
||||
controller.getDuration() - controller.getPosition());
|
||||
Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition));
|
||||
if (currentPosition == PlaybackService.INVALID_TIME ||
|
||||
|
@ -824,14 +679,15 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
return;
|
||||
}
|
||||
|
||||
TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier());
|
||||
String length;
|
||||
if (showTimeLeft) {
|
||||
int remainingTime = TimeSpeedConverter.convert(
|
||||
int remainingTime = converter.convert(
|
||||
media.getDuration() - media.getPosition());
|
||||
|
||||
length = "-" + Converter.getDurationStringLong(remainingTime);
|
||||
} else {
|
||||
int duration = TimeSpeedConverter.convert(media.getDuration());
|
||||
int duration = converter.convert(media.getDuration());
|
||||
length = Converter.getDurationStringLong(duration);
|
||||
}
|
||||
txtvLength.setText(length);
|
||||
|
@ -935,7 +791,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
prog = controller.onSeekBarProgressChanged(seekBar, progress, fromUser, txtvPosition);
|
||||
if (showTimeLeft && prog != 0) {
|
||||
int duration = controller.getDuration();
|
||||
int timeLeft = TimeSpeedConverter.convert(duration - (int) (prog * duration));
|
||||
TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier());
|
||||
int timeLeft = converter.convert(duration - (int) (prog * duration));
|
||||
String length = "-" + Converter.getDurationStringLong(timeLeft);
|
||||
txtvLength.setText(length);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,214 @@
|
|||
package de.danoeh.antennapod.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.util.Converter;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class PlaybackControlsDialog extends DialogFragment {
|
||||
private static final float PLAYBACK_SPEED_STEP = 0.05f;
|
||||
private static final float DEFAULT_MIN_PLAYBACK_SPEED = 0.5f;
|
||||
private static final float DEFAULT_MAX_PLAYBACK_SPEED = 2.5f;
|
||||
private static final String ARGUMENT_IS_PLAYING_VIDEO = "isPlayingVideo";
|
||||
|
||||
private PlaybackController controller;
|
||||
private MaterialDialog dialog;
|
||||
private boolean isPlayingVideo;
|
||||
|
||||
public static PlaybackControlsDialog newInstance(boolean isPlayingVideo) {
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putBoolean(ARGUMENT_IS_PLAYING_VIDEO, isPlayingVideo);
|
||||
PlaybackControlsDialog dialog = new PlaybackControlsDialog();
|
||||
dialog.setArguments(arguments);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public PlaybackControlsDialog() {
|
||||
// Empty constructor required for DialogFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
controller = new PlaybackController(getActivity(), false);
|
||||
controller.init();
|
||||
setupUi();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
controller.release();
|
||||
controller = null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
isPlayingVideo = getArguments() != null && getArguments().getBoolean(ARGUMENT_IS_PLAYING_VIDEO);
|
||||
|
||||
dialog = new MaterialDialog.Builder(getContext())
|
||||
.title(R.string.audio_controls)
|
||||
.customView(R.layout.audio_controls, true)
|
||||
.neutralText(R.string.close_label)
|
||||
.onNeutral((dialog1, which) -> {
|
||||
final SeekBar left = (SeekBar) dialog1.findViewById(R.id.volume_left);
|
||||
final SeekBar right = (SeekBar) dialog1.findViewById(R.id.volume_right);
|
||||
UserPreferences.setVolume(left.getProgress(), right.getProgress());
|
||||
}).build();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private void setupUi() {
|
||||
final SeekBar barPlaybackSpeed = (SeekBar) dialog.findViewById(R.id.playback_speed);
|
||||
final Button butDecSpeed = (Button) dialog.findViewById(R.id.butDecSpeed);
|
||||
butDecSpeed.setOnClickListener(v -> {
|
||||
if (controller != null && controller.canSetPlaybackSpeed()) {
|
||||
barPlaybackSpeed.setProgress(barPlaybackSpeed.getProgress() - 1);
|
||||
} else {
|
||||
VariableSpeedDialog.showGetPluginDialog(getContext());
|
||||
}
|
||||
});
|
||||
final Button butIncSpeed = (Button) dialog.findViewById(R.id.butIncSpeed);
|
||||
butIncSpeed.setOnClickListener(v -> {
|
||||
if (controller != null && controller.canSetPlaybackSpeed()) {
|
||||
barPlaybackSpeed.setProgress(barPlaybackSpeed.getProgress() + 1);
|
||||
} else {
|
||||
VariableSpeedDialog.showGetPluginDialog(getContext());
|
||||
}
|
||||
});
|
||||
|
||||
final TextView txtvPlaybackSpeed = (TextView) dialog.findViewById(R.id.txtvPlaybackSpeed);
|
||||
float currentSpeed = getCurrentSpeed();
|
||||
|
||||
String[] availableSpeeds = UserPreferences.getPlaybackSpeedArray();
|
||||
final float minPlaybackSpeed = availableSpeeds.length > 1 ?
|
||||
Float.valueOf(availableSpeeds[0]) : DEFAULT_MIN_PLAYBACK_SPEED;
|
||||
float maxPlaybackSpeed = availableSpeeds.length > 1 ?
|
||||
Float.valueOf(availableSpeeds[availableSpeeds.length - 1]) : DEFAULT_MAX_PLAYBACK_SPEED;
|
||||
int progressMax = (int) ((maxPlaybackSpeed - minPlaybackSpeed) / PLAYBACK_SPEED_STEP);
|
||||
barPlaybackSpeed.setMax(progressMax);
|
||||
|
||||
txtvPlaybackSpeed.setText(String.format("%.2fx", currentSpeed));
|
||||
barPlaybackSpeed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (controller != null && controller.canSetPlaybackSpeed()) {
|
||||
float playbackSpeed = progress * PLAYBACK_SPEED_STEP + minPlaybackSpeed;
|
||||
controller.setPlaybackSpeed(playbackSpeed);
|
||||
String speedPref = String.format(Locale.US, "%.2f", playbackSpeed);
|
||||
|
||||
if (isPlayingVideo) {
|
||||
UserPreferences.setVideoPlaybackSpeed(speedPref);
|
||||
} else {
|
||||
UserPreferences.setPlaybackSpeed(speedPref);
|
||||
}
|
||||
|
||||
String speedStr = String.format("%.2fx", playbackSpeed);
|
||||
txtvPlaybackSpeed.setText(speedStr);
|
||||
} else if (fromUser) {
|
||||
float speed = getCurrentSpeed();
|
||||
barPlaybackSpeed.post(() -> barPlaybackSpeed.setProgress(
|
||||
(int) ((speed - minPlaybackSpeed) / PLAYBACK_SPEED_STEP)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
if (controller != null && !controller.canSetPlaybackSpeed()) {
|
||||
VariableSpeedDialog.showGetPluginDialog(getContext());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
});
|
||||
barPlaybackSpeed.setProgress((int) ((currentSpeed - minPlaybackSpeed) / PLAYBACK_SPEED_STEP));
|
||||
|
||||
final SeekBar barLeftVolume = (SeekBar) dialog.findViewById(R.id.volume_left);
|
||||
barLeftVolume.setProgress(UserPreferences.getLeftVolumePercentage());
|
||||
final SeekBar barRightVolume = (SeekBar) dialog.findViewById(R.id.volume_right);
|
||||
barRightVolume.setProgress(UserPreferences.getRightVolumePercentage());
|
||||
final CheckBox stereoToMono = (CheckBox) dialog.findViewById(R.id.stereo_to_mono);
|
||||
stereoToMono.setChecked(UserPreferences.stereoToMono());
|
||||
if (controller != null && !controller.canDownmix()) {
|
||||
stereoToMono.setEnabled(false);
|
||||
String sonicOnly = getString(R.string.sonic_only);
|
||||
stereoToMono.setText(stereoToMono.getText() + " [" + sonicOnly + "]");
|
||||
}
|
||||
|
||||
if (UserPreferences.useExoplayer()) {
|
||||
barRightVolume.setEnabled(false);
|
||||
}
|
||||
|
||||
final CheckBox skipSilence = (CheckBox) dialog.findViewById(R.id.skipSilence);
|
||||
skipSilence.setChecked(UserPreferences.isSkipSilence());
|
||||
if (!UserPreferences.useExoplayer()) {
|
||||
skipSilence.setEnabled(false);
|
||||
String exoplayerOnly = getString(R.string.exoplayer_only);
|
||||
skipSilence.setText(skipSilence.getText() + " [" + exoplayerOnly + "]");
|
||||
}
|
||||
skipSilence.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
UserPreferences.setSkipSilence(isChecked);
|
||||
controller.setSkipSilence(isChecked);
|
||||
});
|
||||
|
||||
barLeftVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
controller.setVolume(
|
||||
Converter.getVolumeFromPercentage(progress),
|
||||
Converter.getVolumeFromPercentage(barRightVolume.getProgress()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
});
|
||||
barRightVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
controller.setVolume(
|
||||
Converter.getVolumeFromPercentage(barLeftVolume.getProgress()),
|
||||
Converter.getVolumeFromPercentage(progress));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
});
|
||||
stereoToMono.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
UserPreferences.stereoToMono(isChecked);
|
||||
if (controller != null) {
|
||||
controller.setDownmix(isChecked);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private float getCurrentSpeed() {
|
||||
if (isPlayingVideo) {
|
||||
return UserPreferences.getVideoPlaybackSpeed();
|
||||
}
|
||||
return UserPreferences.getPlaybackSpeed();
|
||||
}
|
||||
}
|
|
@ -596,7 +596,7 @@ public class QueueFragment extends Fragment {
|
|||
String info = queue.size() + getString(R.string.episodes_suffix);
|
||||
if(queue.size() > 0) {
|
||||
long timeLeft = 0;
|
||||
float playbackSpeed = Float.valueOf(UserPreferences.getPlaybackSpeed());
|
||||
float playbackSpeed = UserPreferences.getPlaybackSpeed();
|
||||
for(FeedItem item : queue) {
|
||||
if(item.getMedia() != null) {
|
||||
timeLeft +=
|
||||
|
|
|
@ -109,6 +109,7 @@ public class UserPreferences {
|
|||
public static final String PREF_MEDIA_PLAYER = "prefMediaPlayer";
|
||||
public static final String PREF_MEDIA_PLAYER_EXOPLAYER = "exoplayer";
|
||||
private static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed";
|
||||
private static final String PREF_VIDEO_PLAYBACK_SPEED = "prefVideoPlaybackSpeed";
|
||||
public static final String PREF_PLAYBACK_SKIP_SILENCE = "prefSkipSilence";
|
||||
private static final String PREF_FAST_FORWARD_SECS = "prefFastForwardSecs";
|
||||
private static final String PREF_REWIND_SECS = "prefRewindSecs";
|
||||
|
@ -319,8 +320,24 @@ public class UserPreferences {
|
|||
return prefs.getBoolean(PREF_DELETE_REMOVES_FROM_QUEUE, false);
|
||||
}
|
||||
|
||||
public static String getPlaybackSpeed() {
|
||||
return prefs.getString(PREF_PLAYBACK_SPEED, "1.00");
|
||||
public static float getPlaybackSpeed() {
|
||||
try {
|
||||
return Float.parseFloat(prefs.getString(PREF_PLAYBACK_SPEED, "1.00"));
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, Log.getStackTraceString(e));
|
||||
UserPreferences.setPlaybackSpeed("1.00");
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public static float getVideoPlaybackSpeed() {
|
||||
try {
|
||||
return Float.parseFloat(prefs.getString(PREF_VIDEO_PLAYBACK_SPEED, "1.00"));
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, Log.getStackTraceString(e));
|
||||
UserPreferences.setVideoPlaybackSpeed("1.00");
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isSkipSilence() {
|
||||
|
@ -559,6 +576,12 @@ public class UserPreferences {
|
|||
.apply();
|
||||
}
|
||||
|
||||
public static void setVideoPlaybackSpeed(String speed) {
|
||||
prefs.edit()
|
||||
.putString(PREF_VIDEO_PLAYBACK_SPEED, speed)
|
||||
.apply();
|
||||
}
|
||||
|
||||
public static void setSkipSilence(boolean skipSilence) {
|
||||
prefs.edit()
|
||||
.putBoolean(PREF_PLAYBACK_SKIP_SILENCE, skipSilence)
|
||||
|
|
|
@ -213,8 +213,9 @@ 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);
|
||||
TimeSpeedConverter converter = new TimeSpeedConverter(playbackService.getCurrentPlaybackSpeed());
|
||||
position = converter.convert(position);
|
||||
duration = converter.convert(duration);
|
||||
return Converter.getDurationStringLong(position) + " / "
|
||||
+ Converter.getDurationStringLong(duration);
|
||||
} else {
|
||||
|
|
|
@ -303,14 +303,11 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
Log.d(TAG, "Audiofocus successfully requested");
|
||||
Log.d(TAG, "Resuming/Starting playback");
|
||||
acquireWifiLockIfNecessary();
|
||||
float speed = 1.0f;
|
||||
try {
|
||||
speed = Float.parseFloat(UserPreferences.getPlaybackSpeed());
|
||||
} catch(NumberFormatException e) {
|
||||
Log.e(TAG, Log.getStackTraceString(e));
|
||||
UserPreferences.setPlaybackSpeed(String.valueOf(speed));
|
||||
if (media.getMediaType() == MediaType.VIDEO) {
|
||||
setPlaybackParams(UserPreferences.getVideoPlaybackSpeed(), UserPreferences.isSkipSilence());
|
||||
} else {
|
||||
setPlaybackParams(UserPreferences.getPlaybackSpeed(), UserPreferences.isSkipSilence());
|
||||
}
|
||||
setPlaybackParams(speed, UserPreferences.isSkipSilence());
|
||||
setVolume(UserPreferences.getLeftVolume(), UserPreferences.getRightVolume());
|
||||
|
||||
if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) {
|
||||
|
@ -601,11 +598,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
*/
|
||||
@Override
|
||||
public boolean canSetSpeed() {
|
||||
boolean retVal = false;
|
||||
if (mediaPlayer != null && media != null && media.getMediaType() == MediaType.AUDIO) {
|
||||
retVal = (mediaPlayer).canSetSpeed();
|
||||
}
|
||||
return retVal;
|
||||
return mediaPlayer != null && mediaPlayer.canSetSpeed();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -614,13 +607,11 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
*/
|
||||
private void setSpeedSyncAndSkipSilence(float speed, boolean skipSilence) {
|
||||
playerLock.lock();
|
||||
if (media != null && media.getMediaType() == MediaType.AUDIO) {
|
||||
if (mediaPlayer.canSetSpeed()) {
|
||||
Log.d(TAG, "Playback speed was set to " + speed);
|
||||
callback.playbackSpeedChanged(speed);
|
||||
}
|
||||
mediaPlayer.setPlaybackParams(speed, skipSilence);
|
||||
if (mediaPlayer.canSetSpeed()) {
|
||||
Log.d(TAG, "Playback speed was set to " + speed);
|
||||
callback.playbackSpeedChanged(speed);
|
||||
}
|
||||
mediaPlayer.setPlaybackParams(speed, skipSilence);
|
||||
playerLock.unlock();
|
||||
}
|
||||
|
||||
|
@ -667,10 +658,8 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
*/
|
||||
private void setVolumeSync(float volumeLeft, float volumeRight) {
|
||||
playerLock.lock();
|
||||
if (media != null && media.getMediaType() == MediaType.AUDIO) {
|
||||
mediaPlayer.setVolume(volumeLeft, volumeRight);
|
||||
Log.d(TAG, "Media player volume was set to " + volumeLeft + " " + volumeRight);
|
||||
}
|
||||
mediaPlayer.setVolume(volumeLeft, volumeRight);
|
||||
Log.d(TAG, "Media player volume was set to " + volumeLeft + " " + volumeRight);
|
||||
playerLock.unlock();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,18 +3,19 @@ package de.danoeh.antennapod.core.util;
|
|||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
|
||||
public class TimeSpeedConverter {
|
||||
private TimeSpeedConverter() {
|
||||
private final float speed;
|
||||
|
||||
public TimeSpeedConverter(float speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
public int convert(int time) {
|
||||
boolean timeRespectsSpeed = UserPreferences.timeRespectsSpeed();
|
||||
if (time > 0 && timeRespectsSpeed) {
|
||||
float speed = Float.parseFloat(UserPreferences.getPlaybackSpeed());
|
||||
return (int)(time / speed);
|
||||
}
|
||||
return time;
|
||||
|
|
|
@ -54,7 +54,7 @@ import org.greenrobot.eventbus.ThreadMode;
|
|||
* Communicates with the playback service. GUI classes should use this class to
|
||||
* control playback instead of communicating with the PlaybackService directly.
|
||||
*/
|
||||
public abstract class PlaybackController {
|
||||
public class PlaybackController {
|
||||
|
||||
private static final String TAG = "PlaybackController";
|
||||
|
||||
|
@ -567,7 +567,8 @@ public abstract class PlaybackController {
|
|||
if (fromUser && playbackService != null && media != null) {
|
||||
float prog = progress / ((float) seekBar.getMax());
|
||||
int duration = media.getDuration();
|
||||
int position = TimeSpeedConverter.convert((int) (prog * duration));
|
||||
TimeSpeedConverter converter = new TimeSpeedConverter(playbackService.getCurrentPlaybackSpeed());
|
||||
int position = converter.convert((int) (prog * duration));
|
||||
txtvPosition.setText(Converter.getDurationStringLong(position));
|
||||
return prog;
|
||||
}
|
||||
|
@ -719,6 +720,7 @@ public abstract class PlaybackController {
|
|||
public boolean canSetPlaybackSpeed() {
|
||||
return org.antennapod.audio.MediaPlayer.isPrestoLibraryInstalled(activity.getApplicationContext())
|
||||
|| UserPreferences.useSonic()
|
||||
|| UserPreferences.useExoplayer()
|
||||
|| Build.VERSION.SDK_INT >= 23
|
||||
|| (playbackService != null && playbackService.canSetSpeed());
|
||||
}
|
||||
|
@ -741,7 +743,7 @@ public abstract class PlaybackController {
|
|||
}
|
||||
|
||||
public float getCurrentPlaybackSpeedMultiplier() {
|
||||
if (canSetPlaybackSpeed()) {
|
||||
if (playbackService != null && canSetPlaybackSpeed()) {
|
||||
return playbackService.getCurrentPlaybackSpeed();
|
||||
} else {
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue