From 3e0f084c621e7af0a60a13c701cb94cd3b211041 Mon Sep 17 00:00:00 2001 From: Louis Capitanchik Date: Wed, 27 Sep 2017 16:13:29 +0100 Subject: [PATCH 1/2] Implement 'rate' prop for android devices - Version locked to 6.0+ because that is the version that introduced setPlaybackParams - Ignores rate prop as before on android versions lower than 6.0 --- .../main/java/com/brentvatne/react/ReactVideoView.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index 94a25a0e..099bec33 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -5,6 +5,7 @@ import android.content.res.AssetFileDescriptor; import android.graphics.Matrix; import android.media.MediaPlayer; import android.net.Uri; +import android.os.Build; import android.os.Handler; import android.util.Log; import android.view.MotionEvent; @@ -377,8 +378,11 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP mRate = rate; if (mMediaPlayerValid) { - // TODO: Implement this. - Log.e(ReactVideoViewManager.REACT_CLASS, "Setting playback rate is not yet supported on Android"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + mMediaPlayer.setPlaybackParams(mMediaPlayer.getPlaybackParams().setSpeed(rate)); + } else { + Log.e(ReactVideoViewManager.REACT_CLASS, "Setting playback rate is not yet supported on Android versions below 6.0"); + } } } @@ -388,7 +392,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP setPausedModifier(mPaused); setMutedModifier(mMuted); setProgressUpdateInterval(mProgressUpdateInterval); -// setRateModifier(mRate); + setRateModifier(mRate); } public void setPlayInBackground(final boolean playInBackground) { From fe7766add4ef7690e6572f755df0d59e577b58b3 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Sun, 20 May 2018 23:02:56 -0700 Subject: [PATCH 2/2] Delay all rate changes until the player unpauses --- .../main/java/com/brentvatne/react/ReactVideoView.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index 099bec33..4efe88fd 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -96,6 +96,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP private float mVolume = 1.0f; private float mProgressUpdateInterval = 250.0f; private float mRate = 1.0f; + private float mActiveRate = 1.0f; private boolean mPlayInBackground = false; private boolean mActiveStatePauseStatus = false; private boolean mActiveStatePauseStatusInitialized = false; @@ -344,6 +345,10 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP } else { if (!mMediaPlayer.isPlaying()) { start(); + // Setting the rate unpauses, so we have to wait for an unpause + if (mRate != mActiveRate) { + setRateModifier(mRate); + } // Also Start the Progress Update Handler mProgressUpdateHandler.post(mProgressUpdateRunnable); @@ -379,7 +384,10 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP if (mMediaPlayerValid) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - mMediaPlayer.setPlaybackParams(mMediaPlayer.getPlaybackParams().setSpeed(rate)); + if (!mPaused) { // Applying the rate while paused will cause the video to start + mMediaPlayer.setPlaybackParams(mMediaPlayer.getPlaybackParams().setSpeed(rate)); + mActiveRate = rate; + } } else { Log.e(ReactVideoViewManager.REACT_CLASS, "Setting playback rate is not yet supported on Android versions below 6.0"); }