diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-09-21 09:12:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-21 09:12:23 +0200 |
commit | 349137712055a2810f29d2db132058bff3e0c0c0 (patch) | |
tree | 1ff2f1c8730f18b87511afd3fd1d10f96b44a2c2 /core/src/main/java | |
parent | 64f26d07124ea425488ed8af95c624af1f67e76e (diff) | |
parent | c68f2f75ca3246e2a1ff0395dbbf97d3b3e9dcc8 (diff) | |
download | AntennaPod-349137712055a2810f29d2db132058bff3e0c0c0.zip |
Merge pull request #3354 from ByteHamster/display-buffer-state
Displaying buffer state with ExoPlayer
Diffstat (limited to 'core/src/main/java')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java | 30 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/playback/LocalPSMP.java | 1 |
2 files changed, 29 insertions, 2 deletions
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 f20525f73..7af33f8f9 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 @@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.service.playback; import android.content.Context; import android.net.Uri; +import android.os.Handler; import android.view.SurfaceHolder; import com.google.android.exoplayer2.C; @@ -27,7 +28,6 @@ import com.google.android.exoplayer2.util.Util; import org.antennapod.audio.MediaPlayer; import de.danoeh.antennapod.core.util.playback.IPlayer; - public class ExoPlayerWrapper implements IPlayer { private final Context mContext; private SimpleExoPlayer mExoPlayer; @@ -35,15 +35,35 @@ public class ExoPlayerWrapper implements IPlayer { private MediaPlayer.OnSeekCompleteListener audioSeekCompleteListener; private MediaPlayer.OnCompletionListener audioCompletionListener; private MediaPlayer.OnErrorListener audioErrorListener; + private MediaPlayer.OnBufferingUpdateListener bufferingUpdateListener; + private boolean shouldCheckBufferingUpdates = true; + ExoPlayerWrapper(Context context) { mContext = context; mExoPlayer = createPlayer(); + + Handler handler = new Handler(); // Main thread + handler.postDelayed(new Runnable() { + @Override + public void run() { + if (bufferingUpdateListener != null) { + bufferingUpdateListener.onBufferingUpdate(null, mExoPlayer.getBufferedPercentage()); + } + if (shouldCheckBufferingUpdates) { + handler.postDelayed(this, 2000); + } + } + }, 2000); } private SimpleExoPlayer createPlayer() { + DefaultLoadControl.Builder loadControl = new DefaultLoadControl.Builder(); + loadControl.setBufferDurationsMs(30000, 120000, + DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS, + DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS); SimpleExoPlayer p = ExoPlayerFactory.newSimpleInstance(mContext, new DefaultRenderersFactory(mContext), - new DefaultTrackSelector(), new DefaultLoadControl()); + new DefaultTrackSelector(), loadControl.createDefaultLoadControl()); p.setSeekParameters(SeekParameters.PREVIOUS_SYNC); p.addListener(new Player.EventListener() { @Override @@ -148,12 +168,14 @@ public class ExoPlayerWrapper implements IPlayer { @Override public void release() { + shouldCheckBufferingUpdates = false; if (mExoPlayer != null) { mExoPlayer.release(); } audioSeekCompleteListener = null; audioCompletionListener = null; audioErrorListener = null; + bufferingUpdateListener = null; } @Override @@ -247,4 +269,8 @@ public class ExoPlayerWrapper implements IPlayer { } return mExoPlayer.getVideoFormat().height; } + + void setOnBufferingUpdateListener(MediaPlayer.OnBufferingUpdateListener bufferingUpdateListener) { + this.bufferingUpdateListener = bufferingUpdateListener; + } } 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 5177fa6be..9164f561f 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 @@ -1025,6 +1025,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer { ExoPlayerWrapper ap = (ExoPlayerWrapper) mp; ap.setOnCompletionListener(audioCompletionListener); ap.setOnSeekCompleteListener(audioSeekCompleteListener); + ap.setOnBufferingUpdateListener(audioBufferingUpdateListener); ap.setOnErrorListener(audioErrorListener); } else { Log.w(TAG, "Unknown media player: " + mp); |