From 38d225294f7d0d499f0a4bf2770f14e14f073134 Mon Sep 17 00:00:00 2001 From: RWOverdijk Date: Tue, 25 Jul 2017 16:41:20 +0200 Subject: [PATCH 01/31] add support for onTimedMetaData for android --- .../com/brentvatne/react/ReactVideoView.java | 48 ++++++++++++++++++- 1 file changed, 46 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 94a25a0e..62d53087 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; import android.content.res.AssetFileDescriptor; import android.graphics.Matrix; import android.media.MediaPlayer; +import android.media.TimedMetaData; import android.net.Uri; import android.os.Handler; import android.util.Log; @@ -16,6 +17,8 @@ import com.android.vending.expansion.zipfile.ZipResourceFile; import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.LifecycleEventListener; import com.facebook.react.bridge.WritableMap; +import com.facebook.react.bridge.WritableArray; +import com.facebook.react.bridge.WritableNativeArray; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.events.RCTEventEmitter; import com.yqritc.scalablevideoview.ScalableType; @@ -24,19 +27,28 @@ import com.yqritc.scalablevideoview.ScaleManager; import com.yqritc.scalablevideoview.Size; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; import java.lang.Math; @SuppressLint("ViewConstructor") -public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnPreparedListener, MediaPlayer - .OnErrorListener, MediaPlayer.OnBufferingUpdateListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnInfoListener, LifecycleEventListener, MediaController.MediaPlayerControl { +public class ReactVideoView extends ScalableVideoView implements + MediaPlayer.OnPreparedListener, + MediaPlayer.OnErrorListener, + MediaPlayer.OnBufferingUpdateListener, + MediaPlayer.OnTimedMetaDataAvailableListener, + MediaPlayer.OnCompletionListener, + MediaPlayer.OnInfoListener, + LifecycleEventListener, + MediaController.MediaPlayerControl { public enum Events { EVENT_LOAD_START("onVideoLoadStart"), EVENT_LOAD("onVideoLoad"), EVENT_ERROR("onVideoError"), EVENT_PROGRESS("onVideoProgress"), + EVENT_TIMED_METADATA("onTimedMetadata"), EVENT_SEEK("onVideoSeek"), EVENT_END("onVideoEnd"), EVENT_STALLED("onPlaybackStalled"), @@ -70,6 +82,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP public static final String EVENT_PROP_WIDTH = "width"; public static final String EVENT_PROP_HEIGHT = "height"; public static final String EVENT_PROP_ORIENTATION = "orientation"; + public static final String EVENT_PROP_METADATA = "metadata"; public static final String EVENT_PROP_ERROR = "error"; public static final String EVENT_PROP_WHAT = "what"; @@ -181,6 +194,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnBufferingUpdateListener(this); mMediaPlayer.setOnCompletionListener(this); + mMediaPlayer.setOnTimedMetaDataAvailableListener(this); mMediaPlayer.setOnInfoListener(this); } } @@ -444,6 +458,9 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP } }); } + + // Select track (so we can use it to listen to timed meta data updates) + mp.selectTrack(0); } @Override @@ -478,6 +495,9 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP @Override public void onBufferingUpdate(MediaPlayer mp, int percent) { + // Select track (so we can use it to listen to timed meta data updates) + mp.selectTrack(0); + mVideoBufferedDuration = (int) Math.round((double) (mVideoDuration * percent) / 100.0); } @@ -529,6 +549,30 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP mEventEmitter.receiveEvent(getId(), Events.EVENT_END.toString(), null); } + @Override + public void onTimedMetaDataAvailable(MediaPlayer mp, TimedMetaData data) { + WritableMap event = Arguments.createMap(); + + try { + String rawMeta = new String(data.getMetaData(), "UTF-8"); + WritableMap id3 = Arguments.createMap(); + + id3.putString("value", rawMeta.substring(rawMeta.lastIndexOf("\u0003") + 1)); + id3.putString("identifier", "id3/TDEN"); + + WritableArray metadata = new WritableNativeArray(); + + metadata.pushMap(id3); + + event.putArray(EVENT_PROP_METADATA, metadata); + event.putDouble("target", getId()); + } catch(UnsupportedEncodingException e) { + e.printStackTrace(); + } + + mEventEmitter.receiveEvent(getId(), Events.EVENT_TIMED_METADATA.toString(), event); + } + @Override protected void onDetachedFromWindow() { From aa89683785999f978fa7d60ca1f9a61b6b13f2d0 Mon Sep 17 00:00:00 2001 From: RWOverdijk Date: Tue, 25 Jul 2017 16:53:04 +0200 Subject: [PATCH 02/31] move prop keys for metadata to constants --- .../main/java/com/brentvatne/react/ReactVideoView.java | 9 ++++++--- 1 file changed, 6 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 62d53087..dc513469 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -83,6 +83,9 @@ public class ReactVideoView extends ScalableVideoView implements public static final String EVENT_PROP_HEIGHT = "height"; public static final String EVENT_PROP_ORIENTATION = "orientation"; public static final String EVENT_PROP_METADATA = "metadata"; + public static final String EVENT_PROP_TARGET = "target"; + public static final String EVENT_PROP_METADATA_IDENTIFIER = "identifier"; + public static final String EVENT_PROP_METADATA_VALUE = "value"; public static final String EVENT_PROP_ERROR = "error"; public static final String EVENT_PROP_WHAT = "what"; @@ -557,15 +560,15 @@ public class ReactVideoView extends ScalableVideoView implements String rawMeta = new String(data.getMetaData(), "UTF-8"); WritableMap id3 = Arguments.createMap(); - id3.putString("value", rawMeta.substring(rawMeta.lastIndexOf("\u0003") + 1)); - id3.putString("identifier", "id3/TDEN"); + id3.putString(EVENT_PROP_METADATA_VALUE, rawMeta.substring(rawMeta.lastIndexOf("\u0003") + 1)); + id3.putString(EVENT_PROP_METADATA_IDENTIFIER, "id3/TDEN"); WritableArray metadata = new WritableNativeArray(); metadata.pushMap(id3); event.putArray(EVENT_PROP_METADATA, metadata); - event.putDouble("target", getId()); + event.putDouble(EVENT_PROP_TARGET, getId()); } catch(UnsupportedEncodingException e) { e.printStackTrace(); } From 139c79b8ef0a53bae652a63a52169169284c0834 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Mon, 28 May 2018 18:07:53 -0700 Subject: [PATCH 03/31] Update NewtonSoft JSON to match react-native-windows version --- .../ReactNativeVideo.Net46/ReactNativeVideo.Net46.csproj | 6 +++--- windows/ReactNativeVideo.Net46/packages.config | 4 ++-- windows/ReactNativeVideo/project.json | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/windows/ReactNativeVideo.Net46/ReactNativeVideo.Net46.csproj b/windows/ReactNativeVideo.Net46/ReactNativeVideo.Net46.csproj index df351c95..e59ab904 100644 --- a/windows/ReactNativeVideo.Net46/ReactNativeVideo.Net46.csproj +++ b/windows/ReactNativeVideo.Net46/ReactNativeVideo.Net46.csproj @@ -29,8 +29,8 @@ bin\x86\Release\ - - $(SolutionDir)\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + + $(SolutionDir)\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll True @@ -71,4 +71,4 @@ --> - \ No newline at end of file + diff --git a/windows/ReactNativeVideo.Net46/packages.config b/windows/ReactNativeVideo.Net46/packages.config index 90aba300..2c209cee 100644 --- a/windows/ReactNativeVideo.Net46/packages.config +++ b/windows/ReactNativeVideo.Net46/packages.config @@ -1,4 +1,4 @@  - - \ No newline at end of file + + diff --git a/windows/ReactNativeVideo/project.json b/windows/ReactNativeVideo/project.json index 21494af7..8eec893a 100644 --- a/windows/ReactNativeVideo/project.json +++ b/windows/ReactNativeVideo/project.json @@ -1,7 +1,7 @@ { "dependencies": { "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2", - "Newtonsoft.Json": "9.0.1" + "Newtonsoft.Json": "10.0.3" }, "frameworks": { "uap10.0": {} @@ -14,4 +14,4 @@ "win10-x64": {}, "win10-x64-aot": {} } -} \ No newline at end of file +} From 70d863e3d00b1f66fc8b25f2f4e924befced2815 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Mon, 25 Jun 2018 14:25:12 -0700 Subject: [PATCH 04/31] Allow timed metadata to compile on older SDKs --- .../com/brentvatne/react/ReactVideoView.java | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index dc513469..daacd025 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -37,7 +37,6 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener, MediaPlayer.OnBufferingUpdateListener, - MediaPlayer.OnTimedMetaDataAvailableListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnInfoListener, LifecycleEventListener, @@ -197,8 +196,10 @@ public class ReactVideoView extends ScalableVideoView implements mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnBufferingUpdateListener(this); mMediaPlayer.setOnCompletionListener(this); - mMediaPlayer.setOnTimedMetaDataAvailableListener(this); mMediaPlayer.setOnInfoListener(this); + if (Build.VERSION.SDK_INT >= 23) { + mMediaPlayer.setOnTimedMetaDataAvailableListener(new TimedMetaDataAvailableListener()); + } } } @@ -551,29 +552,34 @@ public class ReactVideoView extends ScalableVideoView implements isCompleted = true; mEventEmitter.receiveEvent(getId(), Events.EVENT_END.toString(), null); } + + // This is not fully tested and does not work for all forms of timed metadata + @TargetApi(23) // 6.0 + public class TimedMetaDataAvailableListener + implements MediaPlayer.OnTimedMetaDataAvailableListener + { + public void onTimedMetaDataAvailable(MediaPlayer mp, TimedMetaData data) { + WritableMap event = Arguments.createMap(); - @Override - public void onTimedMetaDataAvailable(MediaPlayer mp, TimedMetaData data) { - WritableMap event = Arguments.createMap(); + try { + String rawMeta = new String(data.getMetaData(), "UTF-8"); + WritableMap id3 = Arguments.createMap(); - try { - String rawMeta = new String(data.getMetaData(), "UTF-8"); - WritableMap id3 = Arguments.createMap(); + id3.putString(EVENT_PROP_METADATA_VALUE, rawMeta.substring(rawMeta.lastIndexOf("\u0003") + 1)); + id3.putString(EVENT_PROP_METADATA_IDENTIFIER, "id3/TDEN"); - id3.putString(EVENT_PROP_METADATA_VALUE, rawMeta.substring(rawMeta.lastIndexOf("\u0003") + 1)); - id3.putString(EVENT_PROP_METADATA_IDENTIFIER, "id3/TDEN"); + WritableArray metadata = new WritableNativeArray(); - WritableArray metadata = new WritableNativeArray(); + metadata.pushMap(id3); - metadata.pushMap(id3); + event.putArray(EVENT_PROP_METADATA, metadata); + event.putDouble(EVENT_PROP_TARGET, getId()); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } - event.putArray(EVENT_PROP_METADATA, metadata); - event.putDouble(EVENT_PROP_TARGET, getId()); - } catch(UnsupportedEncodingException e) { - e.printStackTrace(); + mEventEmitter.receiveEvent(getId(), Events.EVENT_TIMED_METADATA.toString(), event); } - - mEventEmitter.receiveEvent(getId(), Events.EVENT_TIMED_METADATA.toString(), event); } @Override From 240444c21374d59c97da75134e5e55bd99599cc0 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 10 Jul 2018 15:00:56 +0200 Subject: [PATCH 05/31] Android keep screen on --- .../com/brentvatne/react/ReactVideoView.java | 20 ++++++++++++++++++- 1 file changed, 19 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 954130a1..6568f860 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -9,6 +9,7 @@ import android.os.Build; import android.os.Handler; import android.util.Log; import android.view.MotionEvent; +import android.view.WindowManager; import android.webkit.CookieManager; import android.widget.MediaController; @@ -89,7 +90,6 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP private Handler videoControlHandler = new Handler(); private MediaController mediaController; - private String mSrcUriString = null; private String mSrcType = "mp4"; private ReadableMap mRequestHeaders = null; @@ -591,6 +591,15 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP mMediaPlayerValid = false; super.onDetachedFromWindow(); + + if (mThemedReactContext != null) { + mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + mThemedReactContext.getCurrentActivity().getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + }); + } } @Override @@ -598,6 +607,15 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP super.onAttachedToWindow(); + if (mThemedReactContext != null) { + mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + mThemedReactContext.getCurrentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + }); + } + if(mMainVer>0) { setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders, mMainVer, mPatchVer); } From 2f0b694b38029a6260d5dbe0394133f7f29a6769 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Wed, 11 Jul 2018 12:28:26 +0200 Subject: [PATCH 06/31] Android: MediaPlayer - Prevent screen from dimming --- .../com/brentvatne/react/ReactVideoView.java | 56 +++++++++++++------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index 6568f860..b933c5d1 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -358,10 +358,12 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP if (mPaused) { if (mMediaPlayer.isPlaying()) { pause(); + setPreventScreenFromDimmingFlag(false); } } else { if (!mMediaPlayer.isPlaying()) { start(); + setPreventScreenFromDimmingFlag(true); // Setting the rate unpauses, so we have to wait for an unpause if (mRate != mActiveRate) { setRateModifier(mRate); @@ -457,6 +459,42 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP this.mUseNativeControls = controls; } + public boolean isPreventScreenFromDimmingFlagOn() { + int flags = mThemedReactContext.getCurrentActivity().getWindow().getAttributes().flags; + + if ((flags & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) == 0) { + return false; + } + + return true; + } + + public void setPreventScreenFromDimmingFlag(final boolean state) { + if (!mMediaPlayerValid && mThemedReactContext == null) { + return; + } + + final boolean isFlagOn = isPreventScreenFromDimmingFlagOn(); + + if (state && !isFlagOn) { + mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + mThemedReactContext.getCurrentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + }); + } + + if (!state && isFlagOn) { + mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + mThemedReactContext.getCurrentActivity().getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + }); + } + } + @Override public void onPrepared(MediaPlayer mp) { @@ -592,14 +630,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP mMediaPlayerValid = false; super.onDetachedFromWindow(); - if (mThemedReactContext != null) { - mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - mThemedReactContext.getCurrentActivity().getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } - }); - } + setPreventScreenFromDimmingFlag(false); } @Override @@ -607,14 +638,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP super.onAttachedToWindow(); - if (mThemedReactContext != null) { - mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - mThemedReactContext.getCurrentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } - }); - } + setPreventScreenFromDimmingFlag(true); if(mMainVer>0) { setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders, mMainVer, mPatchVer); From 7e5647d57ffa19c6825566e5375139f3f7b960e3 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Wed, 25 Jul 2018 10:02:04 +0200 Subject: [PATCH 07/31] Android: MediaPlayer - Prevent screen from dimming, fixed bug and simplified code --- .../com/brentvatne/react/ReactVideoView.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index 217f73f5..a8cd590c 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -503,24 +503,12 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP this.mUseNativeControls = controls; } - public boolean isPreventScreenFromDimmingFlagOn() { - int flags = mThemedReactContext.getCurrentActivity().getWindow().getAttributes().flags; - - if ((flags & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) == 0) { - return false; - } - - return true; - } - public void setPreventScreenFromDimmingFlag(final boolean state) { - if (!mMediaPlayerValid && mThemedReactContext == null) { + if (!mMediaPlayerValid || mThemedReactContext == null) { return; } - final boolean isFlagOn = isPreventScreenFromDimmingFlagOn(); - - if (state && !isFlagOn) { + if (state) { mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { @Override public void run() { @@ -529,7 +517,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP }); } - if (!state && isFlagOn) { + if (!state) { mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { @Override public void run() { From ab273ed1b5bc75610f8907b6ce63a14eaa722dd7 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Wed, 25 Jul 2018 10:24:48 +0200 Subject: [PATCH 08/31] Android: MediaPlayer - Prevent screen from dimming, check for activity --- .../java/com/brentvatne/react/ReactVideoView.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index a8cd590c..c3b52f02 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -508,20 +508,25 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP return; } + Activity activity = mThemedReactContext.getCurrentActivity(); + if (activity == null) { + return; + } + if (state) { - mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { + activity.runOnUiThread(new Runnable() { @Override public void run() { - mThemedReactContext.getCurrentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } }); } if (!state) { - mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { + activity.runOnUiThread(new Runnable() { @Override public void run() { - mThemedReactContext.getCurrentActivity().getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + activity.getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } }); } From 99591e45d68a42337c8e8421e19ba52b640b858f Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Wed, 25 Jul 2018 10:34:41 +0200 Subject: [PATCH 09/31] Android: MediaPlayer - Prevent screen from dimming, make variable as final --- android/src/main/java/com/brentvatne/react/ReactVideoView.java | 2 +- 1 file changed, 1 insertion(+), 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 c3b52f02..dddd1507 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -508,7 +508,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP return; } - Activity activity = mThemedReactContext.getCurrentActivity(); + final Activity activity = mThemedReactContext.getCurrentActivity(); if (activity == null) { return; } From 092ba33e95a3bd5c7229b4d25a09bbba28aab462 Mon Sep 17 00:00:00 2001 From: Bryan van Wijk Date: Tue, 31 Jul 2018 17:23:20 +0200 Subject: [PATCH 10/31] Expose DefaultLoadControl parameters Android --- Video.js | 8 +++- .../brentvatne/exoplayer/ExoPlayerConfig.java | 47 +++++++++++++++++++ .../exoplayer/ReactExoplayerView.java | 27 ++++++++++- .../brentvatne/react/ReactVideoPackage.java | 8 +++- 4 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerConfig.java diff --git a/Video.js b/Video.js index f32725f3..71f38723 100644 --- a/Video.js +++ b/Video.js @@ -11,7 +11,13 @@ const styles = StyleSheet.create({ }, }); -export { TextTrackType }; +const { + ExoPlayerConfig +} = NativeModules + +const VideoPlayerConfig = Platform.OS === "android" ? ExoPlayerConfig : undefined; + +export { TextTrackType, VideoPlayerConfig}; export default class Video extends Component { diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerConfig.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerConfig.java new file mode 100644 index 00000000..90c68d01 --- /dev/null +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerConfig.java @@ -0,0 +1,47 @@ +package com.brentvatne.exoplayer; + +import android.content.Context; + +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.Promise; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; + + +public class ExoPlayerConfig extends ReactContextBaseJavaModule { + + public ExoPlayerConfig(ReactApplicationContext reactContext) { + super(reactContext); + } + + @Override + public String getName() { + return "ExoPlayerConfig"; + } + + @ReactMethod + public void setMinBufferMs(final int newMinBufferMs, final Promise promise) { + ReactExoplayerView.setMinBufferMs(newMinBufferMs); + promise.resolve(null); + } + + @ReactMethod + public void setMaxBufferMs(final int newMaxBufferMs, final Promise promise) { + ReactExoplayerView.setMaxBufferMs(newMaxBufferMs); + promise.resolve(null); + } + + @ReactMethod + public void setBufferForPlaybackMs(final int newBufferForPlaybackMs, final Promise promise) { + ReactExoplayerView.setBufferForPlaybackMs(newBufferForPlaybackMs); + promise.resolve(null); + } + + @ReactMethod + public void setBufferForPlaybackAfterRebufferMs(final int newBufferForPlaybackAfterRebufferMs, final Promise promise) { + ReactExoplayerView.setBufferForPlaybackAfterRebufferMs(newBufferForPlaybackAfterRebufferMs); + promise.resolve(null); + } +} diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 487da343..c401e3d2 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -58,6 +58,7 @@ 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.upstream.DataSource; +import com.google.android.exoplayer2.upstream.DefaultAllocator; import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.Util; @@ -90,6 +91,11 @@ class ReactExoplayerView extends FrameLayout implements DEFAULT_COOKIE_MANAGER.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER); } + private static int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS; + private static int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS; + private static int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS; + private static int bufferForPlaybackAfterRebufferMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS; + private final VideoEventEmitter eventEmitter; private Handler mainHandler; @@ -234,7 +240,9 @@ class ReactExoplayerView extends FrameLayout implements if (player == null) { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); - player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, new DefaultLoadControl()); + DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE); + DefaultLoadControl defaultLoadControl = new DefaultLoadControl(allocator, minBufferMs, maxBufferMs, bufferForPlaybackMs, bufferForPlaybackAfterRebufferMs, -1, true); + player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, defaultLoadControl); player.addListener(this); player.setMetadataOutput(this); exoPlayerView.setPlayer(player); @@ -931,4 +939,21 @@ class ReactExoplayerView extends FrameLayout implements public void setUseTextureView(boolean useTextureView) { exoPlayerView.setUseTextureView(useTextureView); } + + + public static void setMinBufferMs(int newMinBufferMs) { + minBufferMs = newMinBufferMs; + } + + public static void setMaxBufferMs(int newMaxBufferMs) { + maxBufferMs = newMaxBufferMs; + } + + public static void setBufferForPlaybackMs(int newBufferForPlaybackMs) { + bufferForPlaybackMs = newBufferForPlaybackMs; + } + + public static void setBufferForPlaybackAfterRebufferMs(int newBufferForPlaybackAfterRebufferMs) { + bufferForPlaybackAfterRebufferMs = newBufferForPlaybackAfterRebufferMs; + } } diff --git a/android-exoplayer/src/main/java/com/brentvatne/react/ReactVideoPackage.java b/android-exoplayer/src/main/java/com/brentvatne/react/ReactVideoPackage.java index 286f972c..34ee588b 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/react/ReactVideoPackage.java +++ b/android-exoplayer/src/main/java/com/brentvatne/react/ReactVideoPackage.java @@ -1,12 +1,14 @@ package com.brentvatne.react; import com.brentvatne.exoplayer.ReactExoplayerViewManager; +import com.brentvatne.exoplayer.ExoPlayerConfig; import com.facebook.react.ReactPackage; import com.facebook.react.bridge.JavaScriptModule; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.uimanager.ViewManager; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -14,7 +16,11 @@ public class ReactVideoPackage implements ReactPackage { @Override public List createNativeModules(ReactApplicationContext reactContext) { - return Collections.emptyList(); + List modules = new ArrayList<>(); + + modules.add(new ExoPlayerConfig(reactContext)); + + return modules; } // Deprecated RN 0.47 From dde27a320e9124278c4d6169d192613480efbb5a Mon Sep 17 00:00:00 2001 From: Bryan van Wijk Date: Wed, 1 Aug 2018 15:58:02 +0200 Subject: [PATCH 11/31] Pass loadControl parameters as video props --- README.md | 25 ++++++++++ Video.js | 14 +++--- .../brentvatne/exoplayer/ExoPlayerConfig.java | 47 ------------------- .../exoplayer/ReactExoplayerView.java | 33 +++++-------- .../exoplayer/ReactExoplayerViewManager.java | 25 ++++++++++ .../brentvatne/react/ReactVideoPackage.java | 8 +--- 6 files changed, 71 insertions(+), 81 deletions(-) delete mode 100644 android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerConfig.java diff --git a/README.md b/README.md index ed6ffae9..5d2cc600 100644 --- a/README.md +++ b/README.md @@ -229,6 +229,7 @@ var styles = StyleSheet.create({ * [textTracks](#texttracks) * [useTextureView](#usetextureview) * [volume](#volume) +* [loadControl](#loadcontrol) ### Event props * [onAudioBecomingNoisy](#onaudiobecomingnoisy) @@ -479,6 +480,30 @@ Adjust the volume. Platforms: all +#### loadControl +Adjust the load control parameters: minBufferMs, maxBufferMs, bufferForPlaybackMs and playbackAfterRebufferMs. + +``` +loadControl={{ + minBufferMs: number, + maxBufferMs: number, + bufferForPlaybackMs: number, + bufferForPlaybackAfterRebufferMs: number, +}} +``` + +Example with default values: +``` +loadControl={{ + minBufferMs: 15000, + maxBufferMs: 50000, + bufferForPlaybackMs: 2500, + bufferForPlaybackAfterRebufferMs: 5000, +}} +``` + +Platforms: AndroidExoplayer + ### Event props #### onAudioBecomingNoisy diff --git a/Video.js b/Video.js index 71f38723..14401078 100644 --- a/Video.js +++ b/Video.js @@ -11,13 +11,7 @@ const styles = StyleSheet.create({ }, }); -const { - ExoPlayerConfig -} = NativeModules - -const VideoPlayerConfig = Platform.OS === "android" ? ExoPlayerConfig : undefined; - -export { TextTrackType, VideoPlayerConfig}; +export { TextTrackType }; export default class Video extends Component { @@ -351,6 +345,12 @@ Video.propTypes = { paused: PropTypes.bool, muted: PropTypes.bool, volume: PropTypes.number, + loadControl: PropTypes.shape({ + minBufferMs: PropTypes.number, + maxBufferMs: PropTypes.number, + bufferForPlaybackMs: PropTypes.number, + bufferForPlaybackAfterRebufferMs: PropTypes.number, + }), stereoPan: PropTypes.number, rate: PropTypes.number, playInBackground: PropTypes.bool, diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerConfig.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerConfig.java deleted file mode 100644 index 90c68d01..00000000 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerConfig.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.brentvatne.exoplayer; - -import android.content.Context; - -import com.facebook.react.bridge.NativeModule; -import com.facebook.react.bridge.Promise; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReactContext; -import com.facebook.react.bridge.ReactContextBaseJavaModule; -import com.facebook.react.bridge.ReactMethod; - - -public class ExoPlayerConfig extends ReactContextBaseJavaModule { - - public ExoPlayerConfig(ReactApplicationContext reactContext) { - super(reactContext); - } - - @Override - public String getName() { - return "ExoPlayerConfig"; - } - - @ReactMethod - public void setMinBufferMs(final int newMinBufferMs, final Promise promise) { - ReactExoplayerView.setMinBufferMs(newMinBufferMs); - promise.resolve(null); - } - - @ReactMethod - public void setMaxBufferMs(final int newMaxBufferMs, final Promise promise) { - ReactExoplayerView.setMaxBufferMs(newMaxBufferMs); - promise.resolve(null); - } - - @ReactMethod - public void setBufferForPlaybackMs(final int newBufferForPlaybackMs, final Promise promise) { - ReactExoplayerView.setBufferForPlaybackMs(newBufferForPlaybackMs); - promise.resolve(null); - } - - @ReactMethod - public void setBufferForPlaybackAfterRebufferMs(final int newBufferForPlaybackAfterRebufferMs, final Promise promise) { - ReactExoplayerView.setBufferForPlaybackAfterRebufferMs(newBufferForPlaybackAfterRebufferMs); - promise.resolve(null); - } -} diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index c401e3d2..878ed261 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -91,11 +91,6 @@ class ReactExoplayerView extends FrameLayout implements DEFAULT_COOKIE_MANAGER.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER); } - private static int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS; - private static int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS; - private static int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS; - private static int bufferForPlaybackAfterRebufferMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS; - private final VideoEventEmitter eventEmitter; private Handler mainHandler; @@ -115,6 +110,11 @@ class ReactExoplayerView extends FrameLayout implements private boolean isBuffering; private float rate = 1f; + private int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS; + private int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS; + private int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS; + private int bufferForPlaybackAfterRebufferMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS; + // Props from React private Uri srcUri; private String extension; @@ -940,20 +940,13 @@ class ReactExoplayerView extends FrameLayout implements exoPlayerView.setUseTextureView(useTextureView); } - - public static void setMinBufferMs(int newMinBufferMs) { - minBufferMs = newMinBufferMs; - } - - public static void setMaxBufferMs(int newMaxBufferMs) { - maxBufferMs = newMaxBufferMs; - } - - public static void setBufferForPlaybackMs(int newBufferForPlaybackMs) { - bufferForPlaybackMs = newBufferForPlaybackMs; - } - - public static void setBufferForPlaybackAfterRebufferMs(int newBufferForPlaybackAfterRebufferMs) { - bufferForPlaybackAfterRebufferMs = newBufferForPlaybackAfterRebufferMs; + public void setLoadControl(int newMinBufferMs, int newMaxBufferMs, int newBufferForPlaybackMs, int newBufferForPlaybackAfterRebufferMs) { + player.release(); + this.player = null; + this.minBufferMs = newMinBufferMs; + this.maxBufferMs = newMaxBufferMs; + this.bufferForPlaybackMs = newBufferForPlaybackMs; + this.bufferForPlaybackAfterRebufferMs = newBufferForPlaybackAfterRebufferMs; + initializePlayer(); } } diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index fbc8a9ad..9611a960 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -11,6 +11,7 @@ import com.facebook.react.common.MapBuilder; import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.annotations.ReactProp; +import com.google.android.exoplayer2.DefaultLoadControl; import com.google.android.exoplayer2.upstream.RawResourceDataSource; import java.util.HashMap; @@ -38,6 +39,11 @@ public class ReactExoplayerViewManager extends ViewGroupManager createNativeModules(ReactApplicationContext reactContext) { - List modules = new ArrayList<>(); - - modules.add(new ExoPlayerConfig(reactContext)); - - return modules; + return Collections.emptyList(); } // Deprecated RN 0.47 From f46a00c4d43adbbc5d4f3d6df12d1a38f504d8ff Mon Sep 17 00:00:00 2001 From: Bryan van Wijk Date: Wed, 1 Aug 2018 16:07:25 +0200 Subject: [PATCH 12/31] Update README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 5d2cc600..3b721e58 100644 --- a/README.md +++ b/README.md @@ -483,6 +483,13 @@ Platforms: all #### loadControl Adjust the load control parameters: minBufferMs, maxBufferMs, bufferForPlaybackMs and playbackAfterRebufferMs. +Property | Description +--- | --- +minBufferMs | The default minimum duration of media that the player will attempt to ensure is buffered at all times, in milliseconds. +maxBufferMs | The default maximum duration of media that the player will attempt to buffer, in milliseconds. +bufferForPlaybackMs | The default duration of media that must be buffered for playback to start or resume following a user action such as a seek, in milliseconds. +playbackAfterRebufferMs | The default duration of media that must be buffered for playback to resume after a rebuffer, in milliseconds. A rebuffer is defined to be caused by buffer depletion rather than a user action. + ``` loadControl={{ minBufferMs: number, From cd75e72180b6424f5c0dd2b4fbdbd9dc7773ce94 Mon Sep 17 00:00:00 2001 From: Bryan van Wijk Date: Thu, 2 Aug 2018 09:20:08 +0200 Subject: [PATCH 13/31] Rename to bufferConfig and use stopPlayback --- README.md | 9 ++--- Video.js | 2 +- .../exoplayer/ReactExoplayerView.java | 13 ++++--- .../exoplayer/ReactExoplayerViewManager.java | 34 +++++++++---------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 3b721e58..f9c49879 100644 --- a/README.md +++ b/README.md @@ -480,8 +480,9 @@ Adjust the volume. Platforms: all -#### loadControl -Adjust the load control parameters: minBufferMs, maxBufferMs, bufferForPlaybackMs and playbackAfterRebufferMs. +#### bufferConfig +Adjust the video load control parameters: minBufferMs, maxBufferMs, bufferForPlaybackMs and playbackAfterRebufferMs. +Note: these values can not be changed after the video component is loaded. Property | Description --- | --- @@ -491,7 +492,7 @@ bufferForPlaybackMs | The default duration of media that must be buffered for pl playbackAfterRebufferMs | The default duration of media that must be buffered for playback to resume after a rebuffer, in milliseconds. A rebuffer is defined to be caused by buffer depletion rather than a user action. ``` -loadControl={{ +bufferConfig={{ minBufferMs: number, maxBufferMs: number, bufferForPlaybackMs: number, @@ -501,7 +502,7 @@ loadControl={{ Example with default values: ``` -loadControl={{ +bufferConfig={{ minBufferMs: 15000, maxBufferMs: 50000, bufferForPlaybackMs: 2500, diff --git a/Video.js b/Video.js index 14401078..5c6cd1d3 100644 --- a/Video.js +++ b/Video.js @@ -345,7 +345,7 @@ Video.propTypes = { paused: PropTypes.bool, muted: PropTypes.bool, volume: PropTypes.number, - loadControl: PropTypes.shape({ + bufferConfig: PropTypes.shape({ minBufferMs: PropTypes.number, maxBufferMs: PropTypes.number, bufferForPlaybackMs: PropTypes.number, diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 878ed261..60f74416 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -940,13 +940,12 @@ class ReactExoplayerView extends FrameLayout implements exoPlayerView.setUseTextureView(useTextureView); } - public void setLoadControl(int newMinBufferMs, int newMaxBufferMs, int newBufferForPlaybackMs, int newBufferForPlaybackAfterRebufferMs) { - player.release(); - this.player = null; - this.minBufferMs = newMinBufferMs; - this.maxBufferMs = newMaxBufferMs; - this.bufferForPlaybackMs = newBufferForPlaybackMs; - this.bufferForPlaybackAfterRebufferMs = newBufferForPlaybackAfterRebufferMs; + public void setBufferConfig(int newMinBufferMs, int newMaxBufferMs, int newBufferForPlaybackMs, int newBufferForPlaybackAfterRebufferMs) { + stopPlayback(); + minBufferMs = newMinBufferMs; + maxBufferMs = newMaxBufferMs; + bufferForPlaybackMs = newBufferForPlaybackMs; + bufferForPlaybackAfterRebufferMs = newBufferForPlaybackAfterRebufferMs; initializePlayer(); } } diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index 9611a960..88839432 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -39,11 +39,11 @@ public class ReactExoplayerViewManager extends ViewGroupManager Date: Thu, 2 Aug 2018 09:23:00 +0200 Subject: [PATCH 14/31] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f9c49879..68d8c3a4 100644 --- a/README.md +++ b/README.md @@ -229,7 +229,7 @@ var styles = StyleSheet.create({ * [textTracks](#texttracks) * [useTextureView](#usetextureview) * [volume](#volume) -* [loadControl](#loadcontrol) +* [bufferConfig](#bufferconfig) ### Event props * [onAudioBecomingNoisy](#onaudiobecomingnoisy) From fd6333f8ac83848b6a0d6295ef5070cdf75b36f5 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Thu, 2 Aug 2018 12:13:16 -0700 Subject: [PATCH 15/31] Various iOS sideloaded text track fixes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13455d3f..057e4a41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Next Version * Basic fullscreen support for Android MediaPlayer [#1138](https://github.com/react-native-community/react-native-video/pull/1138) * Simplify default Android SDK code [#1145](https://github.com/react-native-community/react-native-video/pull/1145) [#1146](https://github.com/react-native-community/react-native-video/pull/1146) +* Various iOS sideloaded text track fixes [#1157](https://github.com/react-native-community/react-native-video/pull/1157) ### Version 3.1.0 * Support sidecar text tracks on iOS [#1109](https://github.com/react-native-community/react-native-video/pull/1109) From 9def59078bbc00b13336bd87618aa5d381e0fbba Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Thu, 2 Aug 2018 12:15:04 -0700 Subject: [PATCH 16/31] Fix #1150 where assets with bundled assets don't work on iOS in release mode --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 057e4a41..936f7047 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Basic fullscreen support for Android MediaPlayer [#1138](https://github.com/react-native-community/react-native-video/pull/1138) * Simplify default Android SDK code [#1145](https://github.com/react-native-community/react-native-video/pull/1145) [#1146](https://github.com/react-native-community/react-native-video/pull/1146) * Various iOS sideloaded text track fixes [#1157](https://github.com/react-native-community/react-native-video/pull/1157) +* Fix #1150 where assets with bundled assets don't work on iOS in release mode [#1162](https://github.com/react-native-community/react-native-video/pull/1162) ### Version 3.1.0 * Support sidecar text tracks on iOS [#1109](https://github.com/react-native-community/react-native-video/pull/1109) From 9ff16ed550e9ad2572df3a50a068b98a70493bcc Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Fri, 3 Aug 2018 14:55:46 -0700 Subject: [PATCH 17/31] Tidy up bufferConfig docs --- README.md | 58 ++++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 68d8c3a4..947f4f2a 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,7 @@ var styles = StyleSheet.create({ ### Configurable props * [allowsExternalPlayback](#allowsexternalplayback) * [audioOnly](#audioonly) +* [bufferConfig](#bufferconfig) * [ignoreSilentSwitch](#ignoresilentswitch) * [muted](#muted) * [paused](#paused) @@ -229,7 +230,6 @@ var styles = StyleSheet.create({ * [textTracks](#texttracks) * [useTextureView](#usetextureview) * [volume](#volume) -* [bufferConfig](#bufferconfig) ### Event props * [onAudioBecomingNoisy](#onaudiobecomingnoisy) @@ -265,6 +265,30 @@ For this to work, the poster prop must be set. Platforms: all +#### bufferConfig +Adjust the buffer settings. This prop takes an object with one or more of the properties listed below. + +This prop can only be set when you are setting a new source, changing it after the media is loaded will cause it to restart. + +Property | Type | Description +--- | --- | --- +minBufferMs | number | The default minimum duration of media that the player will attempt to ensure is buffered at all times, in milliseconds. +maxBufferMs | number | The default maximum duration of media that the player will attempt to buffer, in milliseconds. +bufferForPlaybackMs | number | The default duration of media that must be buffered for playback to start or resume following a user action such as a seek, in milliseconds. +playbackAfterRebufferMs | number | The default duration of media that must be buffered for playback to resume after a rebuffer, in milliseconds. A rebuffer is defined to be caused by buffer depletion rather than a user action. + +Example with default values: +``` +bufferConfig={{ + minBufferMs: 15000, + maxBufferMs: 50000, + bufferForPlaybackMs: 2500, + bufferForPlaybackAfterRebufferMs: 5000 +}} +``` + +Platforms: Android ExoPlayer + #### ignoreSilentSwitch Controls the iOS silent switch behavior * **"inherit" (default)** - Use the default AVPlayer behavior @@ -480,38 +504,6 @@ Adjust the volume. Platforms: all -#### bufferConfig -Adjust the video load control parameters: minBufferMs, maxBufferMs, bufferForPlaybackMs and playbackAfterRebufferMs. -Note: these values can not be changed after the video component is loaded. - -Property | Description ---- | --- -minBufferMs | The default minimum duration of media that the player will attempt to ensure is buffered at all times, in milliseconds. -maxBufferMs | The default maximum duration of media that the player will attempt to buffer, in milliseconds. -bufferForPlaybackMs | The default duration of media that must be buffered for playback to start or resume following a user action such as a seek, in milliseconds. -playbackAfterRebufferMs | The default duration of media that must be buffered for playback to resume after a rebuffer, in milliseconds. A rebuffer is defined to be caused by buffer depletion rather than a user action. - -``` -bufferConfig={{ - minBufferMs: number, - maxBufferMs: number, - bufferForPlaybackMs: number, - bufferForPlaybackAfterRebufferMs: number, -}} -``` - -Example with default values: -``` -bufferConfig={{ - minBufferMs: 15000, - maxBufferMs: 50000, - bufferForPlaybackMs: 2500, - bufferForPlaybackAfterRebufferMs: 5000, -}} -``` - -Platforms: AndroidExoplayer - ### Event props #### onAudioBecomingNoisy From 725497e149cbe2308a3848e9af4dbbbefe9cf210 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Fri, 3 Aug 2018 15:54:18 -0700 Subject: [PATCH 18/31] Don't set isPaused when releasing the player I'm guessing this was a bug as it doesn't make sense that we would set paused to true if the video is playing, and not paused if it wasn't. I believe this is a safe change since we only release the player when the app is closing or we detach (which is going away shortly). We need this since we release the player in order to apply new bufferConfig settings. --- .../main/java/com/brentvatne/exoplayer/ReactExoplayerView.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 60f74416..9ef099cf 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -328,7 +328,6 @@ class ReactExoplayerView extends FrameLayout implements private void releasePlayer() { if (player != null) { - isPaused = player.getPlayWhenReady(); updateResumePosition(); player.release(); player.setMetadataOutput(null); @@ -941,11 +940,11 @@ class ReactExoplayerView extends FrameLayout implements } public void setBufferConfig(int newMinBufferMs, int newMaxBufferMs, int newBufferForPlaybackMs, int newBufferForPlaybackAfterRebufferMs) { - stopPlayback(); minBufferMs = newMinBufferMs; maxBufferMs = newMaxBufferMs; bufferForPlaybackMs = newBufferForPlaybackMs; bufferForPlaybackAfterRebufferMs = newBufferForPlaybackAfterRebufferMs; + releasePlayer(); initializePlayer(); } } From a60a1277b7849edbb0f2424d6c4629711410e52e Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Fri, 3 Aug 2018 15:54:55 -0700 Subject: [PATCH 19/31] Remove extra space --- .../com/brentvatne/exoplayer/ReactExoplayerViewManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index 88839432..9ead70ce 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -220,7 +220,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager Date: Fri, 3 Aug 2018 16:07:57 -0700 Subject: [PATCH 20/31] Android ExoPlayer buffer configuration --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 936f7047..e5142c39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Simplify default Android SDK code [#1145](https://github.com/react-native-community/react-native-video/pull/1145) [#1146](https://github.com/react-native-community/react-native-video/pull/1146) * Various iOS sideloaded text track fixes [#1157](https://github.com/react-native-community/react-native-video/pull/1157) * Fix #1150 where assets with bundled assets don't work on iOS in release mode [#1162](https://github.com/react-native-community/react-native-video/pull/1162) +* Support configuring the buffer on Android ExoPlayer [#1160](https://github.com/react-native-community/react-native-video/pull/1160) ### Version 3.1.0 * Support sidecar text tracks on iOS [#1109](https://github.com/react-native-community/react-native-video/pull/1109) From 91194edbc9a6352326a8bf00d390cf58419ff99c Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Fri, 3 Aug 2018 16:09:57 -0700 Subject: [PATCH 21/31] Clean up bufferConfig notes about when it needs to be applied --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a3880b6e..6e55f39c 100644 --- a/README.md +++ b/README.md @@ -266,8 +266,6 @@ Platforms: all #### bufferConfig Adjust the buffer settings. This prop takes an object with one or more of the properties listed below. -This prop can only be set when you are setting a new source, changing it after the media is loaded will cause it to restart. - Property | Type | Description --- | --- | --- minBufferMs | number | The default minimum duration of media that the player will attempt to ensure is buffered at all times, in milliseconds. @@ -275,6 +273,8 @@ maxBufferMs | number | The default maximum duration of media that the player wil bufferForPlaybackMs | number | The default duration of media that must be buffered for playback to start or resume following a user action such as a seek, in milliseconds. playbackAfterRebufferMs | number | The default duration of media that must be buffered for playback to resume after a rebuffer, in milliseconds. A rebuffer is defined to be caused by buffer depletion rather than a user action. +This prop should only be set when you are setting the source, changing it after the media is loaded will cause it to be reloaded. + Example with default values: ``` bufferConfig={{ From bd48a001c00a8f7af7ca790ed50c318e59bfff6a Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Sun, 5 Aug 2018 17:27:49 -0700 Subject: [PATCH 22/31] Switch to using setKeepScreenOn to prevent screen timeouts --- .../com/brentvatne/react/ReactVideoView.java | 43 ++----------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index dddd1507..b4348114 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -359,7 +359,6 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP } public void setPausedModifier(final boolean paused) { - mPaused = paused; if (!mMediaPlayerValid) { @@ -369,12 +368,10 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP if (mPaused) { if (mMediaPlayer.isPlaying()) { pause(); - setPreventScreenFromDimmingFlag(false); } } else { if (!mMediaPlayer.isPlaying()) { start(); - setPreventScreenFromDimmingFlag(true); // Setting the rate unpauses, so we have to wait for an unpause if (mRate != mActiveRate) { setRateModifier(mRate); @@ -384,6 +381,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP mProgressUpdateHandler.post(mProgressUpdateRunnable); } } + setKeepScreenOn(!mPaused); } // reduces the volume based on stereoPan @@ -503,36 +501,6 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP this.mUseNativeControls = controls; } - public void setPreventScreenFromDimmingFlag(final boolean state) { - if (!mMediaPlayerValid || mThemedReactContext == null) { - return; - } - - final Activity activity = mThemedReactContext.getCurrentActivity(); - if (activity == null) { - return; - } - - if (state) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } - }); - } - - if (!state) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - activity.getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } - }); - } - } - - @Override public void onPrepared(MediaPlayer mp) { @@ -663,27 +631,22 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP @Override protected void onDetachedFromWindow() { - mMediaPlayerValid = false; super.onDetachedFromWindow(); - - setPreventScreenFromDimmingFlag(false); + setKeepScreenOn(false); } @Override protected void onAttachedToWindow() { - super.onAttachedToWindow(); - setPreventScreenFromDimmingFlag(true); - if(mMainVer>0) { setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders, mMainVer, mPatchVer); } else { setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders); } - + setKeepScreenOn(true); } @Override From 3a1d81930e271ffac13ceaba680cb7befc0c7b12 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Sun, 5 Aug 2018 17:34:16 -0700 Subject: [PATCH 23/31] Allow screen to sleep when video finishes --- .../src/main/java/com/brentvatne/react/ReactVideoView.java | 4 +++- 1 file changed, 3 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 b4348114..2a699685 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -624,9 +624,11 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP @Override public void onCompletion(MediaPlayer mp) { - isCompleted = true; mEventEmitter.receiveEvent(getId(), Events.EVENT_END.toString(), null); + if (!mRepeat) { + setKeepScreenOn(false); + } } @Override From 1cc38d1a9c22a6a635e780e98633457ee51ee1c6 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Sun, 5 Aug 2018 17:36:17 -0700 Subject: [PATCH 24/31] Prevent sleep timeout on Android MediaPlayer --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5142c39..551eae46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Various iOS sideloaded text track fixes [#1157](https://github.com/react-native-community/react-native-video/pull/1157) * Fix #1150 where assets with bundled assets don't work on iOS in release mode [#1162](https://github.com/react-native-community/react-native-video/pull/1162) * Support configuring the buffer on Android ExoPlayer [#1160](https://github.com/react-native-community/react-native-video/pull/1160) +* Prevent sleep from sleeping while videos are playing on Android MediaPlayer [#1117](https://github.com/react-native-community/react-native-video/pull/1117) ### Version 3.1.0 * Support sidecar text tracks on iOS [#1109](https://github.com/react-native-community/react-native-video/pull/1109) From 4419b2897d4a03e833243d47ef58237dfe4add52 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Sun, 5 Aug 2018 18:17:11 -0700 Subject: [PATCH 25/31] Update NewtonSoft JSON to match react-native-windows versio --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 551eae46..b237741b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Fix #1150 where assets with bundled assets don't work on iOS in release mode [#1162](https://github.com/react-native-community/react-native-video/pull/1162) * Support configuring the buffer on Android ExoPlayer [#1160](https://github.com/react-native-community/react-native-video/pull/1160) * Prevent sleep from sleeping while videos are playing on Android MediaPlayer [#1117](https://github.com/react-native-community/react-native-video/pull/1117) +* Update NewtonSoft JSON to match react-native-windows version [#1169](https://github.com/react-native-community/react-native-video/pull/1169) ### Version 3.1.0 * Support sidecar text tracks on iOS [#1109](https://github.com/react-native-community/react-native-video/pull/1109) From ba159c3fa74a90472694de58f54af3d7e37eadc2 Mon Sep 17 00:00:00 2001 From: Hampton Maxwell Date: Sun, 5 Aug 2018 18:31:33 -0700 Subject: [PATCH 26/31] Version 3.2.0 --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b237741b..03882943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## Changelog -### Next Version +### Version 3.2.0 * Basic fullscreen support for Android MediaPlayer [#1138](https://github.com/react-native-community/react-native-video/pull/1138) * Simplify default Android SDK code [#1145](https://github.com/react-native-community/react-native-video/pull/1145) [#1146](https://github.com/react-native-community/react-native-video/pull/1146) * Various iOS sideloaded text track fixes [#1157](https://github.com/react-native-community/react-native-video/pull/1157) diff --git a/package.json b/package.json index 7d633256..4f0dc111 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-video", - "version": "3.1.0", + "version": "3.2.0", "description": "A