diff options
author | Taco <SkytkRSfan3895@gmail.com> | 2021-12-10 15:28:09 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 21:28:09 +0100 |
commit | 434cd2b79f2679ca8b01c10723e5663d3b265fb6 (patch) | |
tree | 380a0a85bad237156e2af42d3e83ccdf61492186 /core | |
parent | add003c06b27c01c6a812fa601eb805ca8763d64 (diff) | |
download | AntennaPod-434cd2b79f2679ca8b01c10723e5663d3b265fb6.zip |
Update AndroidX Media and ExoPlayer (#5371)
Diffstat (limited to 'core')
3 files changed, 41 insertions, 21 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/ResizingOkHttpStreamFetcher.java b/core/src/main/java/de/danoeh/antennapod/core/glide/ResizingOkHttpStreamFetcher.java index 11e2f944e..1871723bb 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/glide/ResizingOkHttpStreamFetcher.java +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/ResizingOkHttpStreamFetcher.java @@ -3,12 +3,13 @@ package de.danoeh.antennapod.core.glide; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Build; +import android.util.Log; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.bumptech.glide.Priority; import com.bumptech.glide.integration.okhttp3.OkHttpStreamFetcher; import com.bumptech.glide.load.model.GlideUrl; -import com.google.android.exoplayer2.util.Log; import okhttp3.Call; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -22,7 +23,7 @@ import java.io.InputStream; import java.io.OutputStream; public class ResizingOkHttpStreamFetcher extends OkHttpStreamFetcher { - private static final String TAG = "ResizingOkHttpStreamFetcher"; + private static final String TAG = "ResizingOkHttpStreamFet"; private static final int MAX_DIMENSIONS = 1500; private static final int MAX_FILE_SIZE = 1024 * 1024; // 1 MB 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 7ce06a9fb..d4008b3f2 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 @@ -12,20 +12,21 @@ import com.google.android.exoplayer2.DefaultLoadControl; import com.google.android.exoplayer2.DefaultRenderersFactory; import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.Format; +import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.SeekParameters; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.audio.AudioAttributes; -import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSourceFactory; +import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource; import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory; import com.google.android.exoplayer2.extractor.mp3.Mp3Extractor; import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; +import com.google.android.exoplayer2.trackselection.ExoTrackSelection; import com.google.android.exoplayer2.trackselection.MappingTrackSelector; -import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.ui.DefaultTrackNameProvider; import com.google.android.exoplayer2.ui.TrackNameProvider; @@ -48,6 +49,7 @@ import org.antennapod.audio.MediaPlayer; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.concurrent.TimeUnit; @@ -88,12 +90,12 @@ public class ExoPlayerWrapper implements IPlayer { trackSelector = new DefaultTrackSelector(context); exoPlayer = new SimpleExoPlayer.Builder(context, new DefaultRenderersFactory(context)) .setTrackSelector(trackSelector) - .setLoadControl(loadControl.createDefaultLoadControl()) + .setLoadControl(loadControl.build()) .build(); exoPlayer.setSeekParameters(SeekParameters.EXACT); - exoPlayer.addListener(new Player.EventListener() { + exoPlayer.addListener(new Player.Listener() { @Override - public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { + public void onPlaybackStateChanged(@Player.State int playbackState) { if (audioCompletionListener != null && playbackState == Player.STATE_ENDED) { audioCompletionListener.onCompletion(null); } else if (infoListener != null && playbackState == Player.STATE_BUFFERING) { @@ -119,8 +121,10 @@ public class ExoPlayerWrapper implements IPlayer { } @Override - public void onSeekProcessed() { - if (audioSeekCompleteListener != null) { + public void onPositionDiscontinuity(@NonNull Player.PositionInfo oldPosition, + @NonNull Player.PositionInfo newPosition, + @Player.DiscontinuityReason int reason) { + if (audioSeekCompleteListener != null && reason == Player.DISCONTINUITY_REASON_SEEK) { audioSeekCompleteListener.onSeekComplete(null); } } @@ -157,12 +161,13 @@ public class ExoPlayerWrapper implements IPlayer { @Override public void pause() { - exoPlayer.setPlayWhenReady(false); + exoPlayer.pause(); } @Override public void prepare() throws IllegalStateException { - exoPlayer.prepare(mediaSource, false, true); + exoPlayer.setMediaSource(mediaSource, false); + exoPlayer.prepare(); } @Override @@ -198,25 +203,31 @@ public class ExoPlayerWrapper implements IPlayer { b.setContentType(i); b.setFlags(a.flags); b.setUsage(a.usage); - exoPlayer.setAudioAttributes(b.build()); + exoPlayer.setAudioAttributes(b.build(), false); } public void setDataSource(String s, String user, String password) throws IllegalArgumentException, IllegalStateException { Log.d(TAG, "setDataSource: " + s); - OkHttpDataSourceFactory httpDataSourceFactory = new OkHttpDataSourceFactory( - AntennapodHttpClient.getHttpClient(), ClientConfig.USER_AGENT); + final OkHttpDataSource.Factory httpDataSourceFactory = + new OkHttpDataSource.Factory(AntennapodHttpClient.getHttpClient()) + .setUserAgent(ClientConfig.USER_AGENT); if (!TextUtils.isEmpty(user) && !TextUtils.isEmpty(password)) { - httpDataSourceFactory.getDefaultRequestProperties().set("Authorization", - HttpDownloader.encodeCredentials(user, password, "ISO-8859-1")); + final HashMap<String, String> requestProperties = new HashMap<>(); + requestProperties.put( + "Authorization", + HttpDownloader.encodeCredentials(user, password, "ISO-8859-1") + ); + httpDataSourceFactory.setDefaultRequestProperties(requestProperties); } DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, null, httpDataSourceFactory); DefaultExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); extractorsFactory.setConstantBitrateSeekingEnabled(true); extractorsFactory.setMp3ExtractorFlags(Mp3Extractor.FLAG_DISABLE_ID3_METADATA); ProgressiveMediaSource.Factory f = new ProgressiveMediaSource.Factory(dataSourceFactory, extractorsFactory); - mediaSource = f.createMediaSource(Uri.parse(s)); + final MediaItem mediaItem = MediaItem.fromUri(Uri.parse(s)); + mediaSource = f.createMediaSource(mediaItem); } @Override @@ -231,7 +242,8 @@ public class ExoPlayerWrapper implements IPlayer { @Override public void setPlaybackParams(float speed, boolean skipSilence) { - playbackParameters = new PlaybackParameters(speed, playbackParameters.pitch, skipSilence); + playbackParameters = new PlaybackParameters(speed, playbackParameters.pitch); + exoPlayer.setSkipSilenceEnabled(skipSilence); exoPlayer.setPlaybackParameters(playbackParameters); } @@ -252,7 +264,7 @@ public class ExoPlayerWrapper implements IPlayer { @Override public void start() { - exoPlayer.setPlayWhenReady(true); + exoPlayer.play(); // Can't set params when paused - so always set it on start in case they changed exoPlayer.setPlaybackParameters(playbackParameters); } @@ -312,7 +324,7 @@ public class ExoPlayerWrapper implements IPlayer { TrackSelectionArray trackSelections = exoPlayer.getCurrentTrackSelections(); List<Format> availableFormats = getFormats(); for (int i = 0; i < trackSelections.length; i++) { - TrackSelection track = trackSelections.get(i); + ExoTrackSelection track = (ExoTrackSelection) trackSelections.get(i); if (track == null) { continue; } 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 d5e0140d0..22378e01a 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 @@ -1231,7 +1231,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_FAST_FORWARD | PlaybackStateCompat.ACTION_SKIP_TO_NEXT - | PlaybackStateCompat.ACTION_SEEK_TO; + | PlaybackStateCompat.ACTION_SEEK_TO + | PlaybackStateCompat.ACTION_SET_PLAYBACK_SPEED; if (useSkipToPreviousForRewindInLockscreen()) { // Workaround to fool Android so that Lockscreen will expose a skip-to-previous button, @@ -1888,6 +1889,12 @@ public class PlaybackService extends MediaBrowserServiceCompat { } @Override + public void onSetPlaybackSpeed(float speed) { + Log.d(TAG, "onSetPlaybackSpeed()"); + setSpeed(speed); + } + + @Override public boolean onMediaButtonEvent(final Intent mediaButton) { Log.d(TAG, "onMediaButtonEvent(" + mediaButton + ")"); if (mediaButton != null) { |