Enable ExoPlayer feature to skip silence
SetSpeed was change to SetPlaybackParams which contain speed and a switch to skip silence. For Players that fo not support this the call is ignored or only SetSpeed is used. It is only working if ExoPlayeris used Default is OFF
This commit is contained in:
parent
33603f8edd
commit
1d8509fd8a
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -34,6 +34,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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue