diff options
10 files changed, 33 insertions, 18 deletions
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 c44999c88..9573103ea 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 @@ -103,7 +103,9 @@ public class UserPreferences { // Mediaplayer 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"; + 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"; private static final String PREF_QUEUE_LOCKED = "prefQueueLocked"; @@ -317,6 +319,10 @@ public class UserPreferences { return prefs.getString(PREF_PLAYBACK_SPEED, "1.00"); } + public static boolean isSkipSilence() { + return prefs.getBoolean(PREF_PLAYBACK_SKIP_SILENCE, false); + } + public static String[] getPlaybackSpeedArray() { return readPlaybackSpeedArray(prefs.getString(PREF_PLAYBACK_SPEED_ARRAY, null)); } @@ -647,7 +653,7 @@ public class UserPreferences { } public static boolean useExoplayer() { - return prefs.getString(PREF_MEDIA_PLAYER, "sonic").equals("exoplayer"); + return prefs.getString(PREF_MEDIA_PLAYER, "sonic").equals(PREF_MEDIA_PLAYER_EXOPLAYER); } public static void enableSonic() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java index 63f9beac8..281bd064b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java @@ -25,7 +25,6 @@ import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.util.Util; import org.antennapod.audio.MediaPlayer; - import de.danoeh.antennapod.core.util.playback.IPlayer; @@ -192,9 +191,9 @@ public class ExoPlayerWrapper implements IPlayer { } @Override - public void setPlaybackSpeed(float v) { + public void setPlaybackParams(float speed, boolean skipSilence) { PlaybackParameters params = mExoPlayer.getPlaybackParameters(); - mExoPlayer.setPlaybackParameters(new PlaybackParameters(v, params.pitch)); + mExoPlayer.setPlaybackParameters(new PlaybackParameters(speed, params.pitch, skipSilence)); } @Override diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java index c7948b157..9c519eb8a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java @@ -236,7 +236,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { Log.e(TAG, Log.getStackTraceString(e)); UserPreferences.setPlaybackSpeed(String.valueOf(speed)); } - setSpeed(speed); + setPlaybackParams(speed, UserPreferences.isSkipSilence()); setVolume(UserPreferences.getLeftVolume(), UserPreferences.getRightVolume()); if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) { @@ -537,14 +537,14 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { * Sets the playback speed. * This method is executed on the caller's thread. */ - private void setSpeedSync(float speed) { + private void setSpeedSyncAndSkipSilence(float speed, boolean skipSilence) { playerLock.lock(); if (media != null && media.getMediaType() == MediaType.AUDIO) { if (mediaPlayer.canSetSpeed()) { - mediaPlayer.setPlaybackSpeed(speed); Log.d(TAG, "Playback speed was set to " + speed); callback.playbackSpeedChanged(speed); } + mediaPlayer.setPlaybackParams(speed, skipSilence); } playerLock.unlock(); } @@ -554,8 +554,8 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { * This method is executed on an internal executor service. */ @Override - public void setSpeed(final float speed) { - executor.submit(() -> setSpeedSync(speed)); + public void setPlaybackParams(final float speed, final boolean skipSilence) { + executor.submit(() -> setSpeedSyncAndSkipSilence(speed, skipSilence)); } /** diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index aea043a91..79fbff18d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -1629,7 +1629,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { } public void setSpeed(float speed) { - mediaPlayer.setSpeed(speed); + mediaPlayer.setPlaybackParams(speed, UserPreferences.isSkipSilence()); } public void setVolume(float leftVolume, float rightVolume) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java index a2481b801..b8198fa63 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java @@ -148,10 +148,12 @@ public abstract class PlaybackServiceMediaPlayer { public abstract boolean canSetSpeed(); /** - * Sets the playback speed. + * Sets the playback parameters. + * - Speed + * - SkipSilence (ExoPlayer only) * This method is executed on an internal executor service. */ - public abstract void setSpeed(float speed); + public abstract void setPlaybackParams(final float speed, final boolean skipSilence); /** * Returns the current playback speed. If the playback speed could not be retrieved, 1 is returned. diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/AudioPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/AudioPlayer.java index 16d05dbb9..2b3f38841 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/AudioPlayer.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/AudioPlayer.java @@ -35,6 +35,14 @@ public class AudioPlayer extends MediaPlayer implements IPlayer { } @Override + public void setPlaybackParams(float speed, boolean skipSilence) { + if(canSetSpeed()) { + setPlaybackSpeed(speed); + } + //Default player does not support silence skipping + } + + @Override protected boolean useSonic() { return UserPreferences.useSonic(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/IPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/IPlayer.java index a372f4241..c2b768ea8 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/IPlayer.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/IPlayer.java @@ -37,7 +37,7 @@ public interface IPlayer { void setDisplay(SurfaceHolder sh); - void setPlaybackSpeed(float f); + void setPlaybackParams(float speed, boolean skipSilence); void setDownmix(boolean enable); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/VideoPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/VideoPlayer.java index 1d04fb878..f3c1c4f59 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/VideoPlayer.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/VideoPlayer.java @@ -22,9 +22,8 @@ public class VideoPlayer extends MediaPlayer implements IPlayer { } @Override - public void setPlaybackSpeed(float f) { - Log.e(TAG, "Setting playback speed unsupported in video player"); - throw new UnsupportedOperationException("Setting playback speed unsupported in video player"); + public void setPlaybackParams(float speed, boolean skipSilence) { + //Ignore this for non ExoPlayer implementations } @Override diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 9dd928311..8ed70bb67 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -466,6 +466,7 @@ <string name="media_player_builtin">Built-in Android player</string> <string name="media_player_sonic" translatable="false">Sonic Media Player</string> <string name="media_player_exoplayer" translatable="false">ExoPlayer</string> + <string name="pref_skip_silence_title" >Skip Silence in Audio</string> <string name="pref_videoBehavior_title">Upon exiting video</string> <string name="pref_videoBehavior_sum">Behavior when leaving video playback</string> <string name="stop_playback">Stop playback</string> diff --git a/core/src/play/java/de/danoeh/antennapod/core/service/playback/RemotePSMP.java b/core/src/play/java/de/danoeh/antennapod/core/service/playback/RemotePSMP.java index 79e058d0c..487849ef5 100644 --- a/core/src/play/java/de/danoeh/antennapod/core/service/playback/RemotePSMP.java +++ b/core/src/play/java/de/danoeh/antennapod/core/service/playback/RemotePSMP.java @@ -515,8 +515,8 @@ public class RemotePSMP extends PlaybackServiceMediaPlayer { } @Override - public void setSpeed(float speed) { - throw new UnsupportedOperationException("Setting playback speed unsupported for Remote Playback"); + public void setPlaybackParams(float speed, boolean skipSilence) { + //Can be safely ignored as neither set speed not skipSilence is supported } @Override |