Playback speed fixes (#7013)

- Remove video-specific playback speed (no longer needed now that we have per-podcast speed)
- Respect changed speed setting on settings page even if the service is not running
- Do not change global speed when feed setting is updated
This commit is contained in:
ByteHamster 2024-03-22 19:44:14 +01:00 committed by GitHub
parent 0a6b7ed699
commit bd17373c18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 84 deletions

View File

@ -86,6 +86,7 @@ public class VariableSpeedDialog extends BottomSheetDialogFragment {
View root = View.inflate(getContext(), R.layout.speed_select_dialog, null); View root = View.inflate(getContext(), R.layout.speed_select_dialog, null);
speedSeekBar = root.findViewById(R.id.speed_seek_bar); speedSeekBar = root.findViewById(R.id.speed_seek_bar);
speedSeekBar.setProgressChangedListener(multiplier -> { speedSeekBar.setProgressChangedListener(multiplier -> {
UserPreferences.setPlaybackSpeed(multiplier);
if (controller != null) { if (controller != null) {
controller.setPlaybackSpeed(multiplier); controller.setPlaybackSpeed(multiplier);
} }
@ -148,10 +149,11 @@ public class VariableSpeedDialog extends BottomSheetDialogFragment {
return true; return true;
}); });
holder.chip.setOnClickListener(v -> { holder.chip.setOnClickListener(v -> {
UserPreferences.setPlaybackSpeed(speed);
new Handler(Looper.getMainLooper()).postDelayed(() -> { new Handler(Looper.getMainLooper()).postDelayed(() -> {
if (controller != null) { if (controller != null) {
dismiss();
controller.setPlaybackSpeed(speed); controller.setPlaybackSpeed(speed);
dismiss();
} }
}, 200); }, 200);
}); });

View File

@ -1,54 +1,36 @@
package de.danoeh.antennapod.core.feed.util; package de.danoeh.antennapod.core.feed.util;
import android.util.Log;
import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.Feed;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.model.feed.FeedMedia;
import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.model.feed.FeedPreferences;
import de.danoeh.antennapod.model.playback.MediaType;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.model.playback.Playable; import de.danoeh.antennapod.model.playback.Playable;
import static de.danoeh.antennapod.model.feed.FeedPreferences.SPEED_USE_GLOBAL;
/** /**
* Utility class to use the appropriate playback speed based on {@link PlaybackPreferences} * Utility class to use the appropriate playback speed based on {@link PlaybackPreferences}
*/ */
public final class PlaybackSpeedUtils { public abstract class PlaybackSpeedUtils {
private static final String TAG = "PlaybackSpeedUtils";
private PlaybackSpeedUtils() {
}
/** /**
* Returns the currently configured playback speed for the specified media. * Returns the currently configured playback speed for the specified media.
*/ */
public static float getCurrentPlaybackSpeed(Playable media) { public static float getCurrentPlaybackSpeed(Playable media) {
float playbackSpeed = SPEED_USE_GLOBAL; float playbackSpeed = FeedPreferences.SPEED_USE_GLOBAL;
MediaType mediaType = null; if (media instanceof FeedMedia) {
FeedMedia feedMedia = (FeedMedia) media;
if (media != null) { if (PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == feedMedia.getId()) {
mediaType = media.getMediaType();
playbackSpeed = PlaybackPreferences.getCurrentlyPlayingTemporaryPlaybackSpeed(); playbackSpeed = PlaybackPreferences.getCurrentlyPlayingTemporaryPlaybackSpeed();
}
if (playbackSpeed == SPEED_USE_GLOBAL && media instanceof FeedMedia) { if (playbackSpeed == FeedPreferences.SPEED_USE_GLOBAL && feedMedia.getItem() != null) {
FeedItem item = ((FeedMedia) media).getItem(); Feed feed = feedMedia.getItem().getFeed();
if (item != null) {
Feed feed = item.getFeed();
if (feed != null && feed.getPreferences() != null) { if (feed != null && feed.getPreferences() != null) {
playbackSpeed = feed.getPreferences().getFeedPlaybackSpeed(); playbackSpeed = feed.getPreferences().getFeedPlaybackSpeed();
} else {
Log.d(TAG, "Can not get feed specific playback speed: " + feed);
} }
} }
} }
if (playbackSpeed == FeedPreferences.SPEED_USE_GLOBAL) {
playbackSpeed = UserPreferences.getPlaybackSpeed();
} }
if (playbackSpeed == SPEED_USE_GLOBAL) {
playbackSpeed = UserPreferences.getPlaybackSpeed(mediaType);
}
return playbackSpeed; return playbackSpeed;
} }
@ -57,12 +39,15 @@ public final class PlaybackSpeedUtils {
*/ */
public static FeedPreferences.SkipSilence getCurrentSkipSilencePreference(Playable media) { public static FeedPreferences.SkipSilence getCurrentSkipSilencePreference(Playable media) {
FeedPreferences.SkipSilence skipSilence = FeedPreferences.SkipSilence.GLOBAL; FeedPreferences.SkipSilence skipSilence = FeedPreferences.SkipSilence.GLOBAL;
if (media != null) { if (media instanceof FeedMedia) {
FeedMedia feedMedia = (FeedMedia) media;
if (PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == feedMedia.getId()) {
skipSilence = PlaybackPreferences.getCurrentlyPlayingTemporarySkipSilence(); skipSilence = PlaybackPreferences.getCurrentlyPlayingTemporarySkipSilence();
if (skipSilence == FeedPreferences.SkipSilence.GLOBAL && media instanceof FeedMedia) { }
FeedItem item = ((FeedMedia) media).getItem(); if (skipSilence == FeedPreferences.SkipSilence.GLOBAL && feedMedia.getItem() != null) {
if (item != null && item.getFeed() != null && item.getFeed().getPreferences() != null) { Feed feed = feedMedia.getItem().getFeed();
skipSilence = item.getFeed().getPreferences().getFeedSkipSilence(); if (feed != null && feed.getPreferences() != null) {
skipSilence = feed.getPreferences().getFeedSkipSilence();
} }
} }
} }

View File

@ -1616,18 +1616,17 @@ public class PlaybackService extends MediaBrowserServiceCompat {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void speedPresetChanged(SpeedPresetChangedEvent event) { public void speedPresetChanged(SpeedPresetChangedEvent event) {
if (getPlayable() instanceof FeedMedia) { if (getPlayable() instanceof FeedMedia) {
if (((FeedMedia) getPlayable()).getItem().getFeed().getId() == event.getFeedId()) { FeedMedia playable = (FeedMedia) getPlayable();
if (playable.getItem().getFeed().getId() == event.getFeedId()) {
if (event.getSpeed() == SPEED_USE_GLOBAL) { if (event.getSpeed() == SPEED_USE_GLOBAL) {
setSpeed(UserPreferences.getPlaybackSpeed(getPlayable().getMediaType())); setSpeed(UserPreferences.getPlaybackSpeed());
setSkipSilence(UserPreferences.isSkipSilence());
} else { } else {
setSpeed(event.getSpeed()); setSpeed(event.getSpeed());
FeedPreferences.SkipSilence skipSilence = event.getSkipSilence(); }
if (skipSilence == FeedPreferences.SkipSilence.GLOBAL) { if (event.getSkipSilence() == FeedPreferences.SkipSilence.GLOBAL) {
setSkipSilence(UserPreferences.isSkipSilence()); setSkipSilence(UserPreferences.isSkipSilence());
} else { } else {
setSkipSilence(skipSilence == FeedPreferences.SkipSilence.AGGRESSIVE); setSkipSilence(event.getSkipSilence() == FeedPreferences.SkipSilence.AGGRESSIVE);
}
} }
} }
} }
@ -1637,10 +1636,10 @@ public class PlaybackService extends MediaBrowserServiceCompat {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void skipIntroEndingPresetChanged(SkipIntroEndingChangedEvent event) { public void skipIntroEndingPresetChanged(SkipIntroEndingChangedEvent event) {
if (getPlayable() instanceof FeedMedia) { if (getPlayable() instanceof FeedMedia) {
if (((FeedMedia) getPlayable()).getItem().getFeed().getId() == event.getFeedId()) { FeedMedia playable = (FeedMedia) getPlayable();
if (playable.getItem().getFeed().getId() == event.getFeedId()) {
if (event.getSkipEnding() != 0) { if (event.getSkipEnding() != 0) {
FeedPreferences feedPreferences FeedPreferences feedPreferences = playable.getItem().getFeed().getPreferences();
= ((FeedMedia) getPlayable()).getItem().getFeed().getPreferences();
feedPreferences.setFeedSkipIntro(event.getSkipIntro()); feedPreferences.setFeedSkipIntro(event.getSkipIntro());
feedPreferences.setFeedSkipEnding(event.getSkipEnding()); feedPreferences.setFeedSkipEnding(event.getSkipEnding());
} }
@ -1684,18 +1683,11 @@ public class PlaybackService extends MediaBrowserServiceCompat {
public void setSpeed(float speed) { public void setSpeed(float speed) {
PlaybackPreferences.setCurrentlyPlayingTemporaryPlaybackSpeed(speed); PlaybackPreferences.setCurrentlyPlayingTemporaryPlaybackSpeed(speed);
if (currentMediaType == MediaType.VIDEO) {
UserPreferences.setVideoPlaybackSpeed(speed);
} else {
UserPreferences.setPlaybackSpeed(speed);
}
mediaPlayer.setPlaybackParams(speed, getCurrentSkipSilence()); mediaPlayer.setPlaybackParams(speed, getCurrentSkipSilence());
} }
public void setSkipSilence(boolean skipSilence) { public void setSkipSilence(boolean skipSilence) {
PlaybackPreferences.setCurrentlyPlayingTemporarySkipSilence(skipSilence); PlaybackPreferences.setCurrentlyPlayingTemporarySkipSilence(skipSilence);
UserPreferences.setSkipSilence(skipSilence);
mediaPlayer.setPlaybackParams(getCurrentPlaybackSpeed(), skipSilence); mediaPlayer.setPlaybackParams(getCurrentPlaybackSpeed(), skipSilence);
} }

View File

@ -33,7 +33,6 @@ import de.danoeh.antennapod.model.feed.FeedCounter;
import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.model.feed.FeedPreferences;
import de.danoeh.antennapod.model.feed.SortOrder; import de.danoeh.antennapod.model.feed.SortOrder;
import de.danoeh.antennapod.model.feed.SubscriptionsFilter; import de.danoeh.antennapod.model.feed.SubscriptionsFilter;
import de.danoeh.antennapod.model.playback.MediaType;
/** /**
* Provides access to preferences set by the user in the settings screen. A * Provides access to preferences set by the user in the settings screen. A
@ -118,7 +117,6 @@ public class UserPreferences {
// Mediaplayer // Mediaplayer
private static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed"; 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"; public static final String PREF_PLAYBACK_SKIP_SILENCE = "prefSkipSilence";
private static final String PREF_FAST_FORWARD_SECS = "prefFastForwardSecs"; private static final String PREF_FAST_FORWARD_SECS = "prefFastForwardSecs";
private static final String PREF_REWIND_SECS = "prefRewindSecs"; private static final String PREF_REWIND_SECS = "prefRewindSecs";
@ -131,8 +129,6 @@ public class UserPreferences {
public static final int EPISODE_CLEANUP_DEFAULT = 0; public static final int EPISODE_CLEANUP_DEFAULT = 0;
// Constants // Constants
public static final int NOTIFICATION_BUTTON_REWIND = 0;
public static final int NOTIFICATION_BUTTON_FAST_FORWARD = 1;
public static final int NOTIFICATION_BUTTON_SKIP = 2; public static final int NOTIFICATION_BUTTON_SKIP = 2;
public static final int NOTIFICATION_BUTTON_NEXT_CHAPTER = 3; public static final int NOTIFICATION_BUTTON_NEXT_CHAPTER = 3;
public static final int NOTIFICATION_BUTTON_PLAYBACK_SPEED = 4; public static final int NOTIFICATION_BUTTON_PLAYBACK_SPEED = 4;
@ -406,15 +402,7 @@ public class UserPreferences {
return prefs.getBoolean(PREF_DELETE_REMOVES_FROM_QUEUE, false); return prefs.getBoolean(PREF_DELETE_REMOVES_FROM_QUEUE, false);
} }
public static float getPlaybackSpeed(MediaType mediaType) { public static float getPlaybackSpeed() {
if (mediaType == MediaType.VIDEO) {
return getVideoPlaybackSpeed();
} else {
return getAudioPlaybackSpeed();
}
}
private static float getAudioPlaybackSpeed() {
try { try {
return Float.parseFloat(prefs.getString(PREF_PLAYBACK_SPEED, "1.00")); return Float.parseFloat(prefs.getString(PREF_PLAYBACK_SPEED, "1.00"));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
@ -424,16 +412,6 @@ public class UserPreferences {
} }
} }
private 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.0f);
return 1.0f;
}
}
public static boolean isSkipSilence() { public static boolean isSkipSilence() {
return prefs.getBoolean(PREF_PLAYBACK_SKIP_SILENCE, false); return prefs.getBoolean(PREF_PLAYBACK_SKIP_SILENCE, false);
} }
@ -612,10 +590,6 @@ public class UserPreferences {
prefs.edit().putString(PREF_PLAYBACK_SPEED, String.valueOf(speed)).apply(); prefs.edit().putString(PREF_PLAYBACK_SPEED, String.valueOf(speed)).apply();
} }
public static void setVideoPlaybackSpeed(float speed) {
prefs.edit().putString(PREF_VIDEO_PLAYBACK_SPEED, String.valueOf(speed)).apply();
}
public static void setSkipSilence(boolean skipSilence) { public static void setSkipSilence(boolean skipSilence) {
prefs.edit().putBoolean(PREF_PLAYBACK_SKIP_SILENCE, skipSilence).apply(); prefs.edit().putBoolean(PREF_PLAYBACK_SKIP_SILENCE, skipSilence).apply();
} }