From d7c44104bd9a4ec353b66d88e20300e1a1ff27bf Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Fri, 22 Jun 2018 12:57:29 -0700 Subject: [PATCH] Catch exception when setting the rate on some devices A more elegant fix would be nice but is more work than it's worth at this time. --- .../java/com/brentvatne/react/ReactVideoView.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index a2e0f276..d8127879 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -410,8 +410,16 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP if (mMediaPlayerValid) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!mPaused) { // Applying the rate while paused will cause the video to start - mMediaPlayer.setPlaybackParams(mMediaPlayer.getPlaybackParams().setSpeed(rate)); - mActiveRate = rate; + /* Per https://stackoverflow.com/questions/39442522/setplaybackparams-causes-illegalstateexception + * Some devices throw an IllegalStateException if you set the rate without first calling reset() + * TODO: Call reset() then reinitialize the player + */ + try { + mMediaPlayer.setPlaybackParams(mMediaPlayer.getPlaybackParams().setSpeed(rate)); + mActiveRate = rate; + } catch (Exception e) { + Log.e(ReactVideoViewManager.REACT_CLASS, "Unable to set rate, unsupported on this device"); + } } } else { Log.e(ReactVideoViewManager.REACT_CLASS, "Setting playback rate is not yet supported on Android versions below 6.0");