diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 8ef2afca..d62b38fc 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -116,7 +116,7 @@ import java.util.concurrent.TimeUnit; import java.lang.Integer; @SuppressLint("ViewConstructor") -class ReactExoplayerView extends FrameLayout implements +public class ReactExoplayerView extends FrameLayout implements LifecycleEventListener, Player.Listener, BandwidthMeter.EventListener, diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoPackage.java b/android/src/main/java/com/brentvatne/react/ReactVideoPackage.java index 23bedad6..95afa512 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoPackage.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoPackage.java @@ -9,6 +9,7 @@ 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; @@ -25,9 +26,12 @@ public class ReactVideoPackage implements ReactPackage { @Override public List createNativeModules(ReactApplicationContext reactContext) { - return Collections.singletonList( - new VideoDecoderPropertiesModule(reactContext) - ); + List modules = new ArrayList(); + + modules.add(new VideoDecoderPropertiesModule(reactContext)); + modules.add(new VideoManagerModule(reactContext)); + + return modules; } // Deprecated RN 0.47 diff --git a/android/src/main/java/com/brentvatne/react/VideoManagerModule.java b/android/src/main/java/com/brentvatne/react/VideoManagerModule.java new file mode 100644 index 00000000..bf5b6c1f --- /dev/null +++ b/android/src/main/java/com/brentvatne/react/VideoManagerModule.java @@ -0,0 +1,39 @@ +package com.brentvatne.react; + +import android.view.View; + +import androidx.annotation.NonNull; + +import com.brentvatne.exoplayer.ReactExoplayerView; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.uimanager.UIManagerModule; + +public class VideoManagerModule extends ReactContextBaseJavaModule { + ReactApplicationContext reactContext; + + @NonNull + @Override + public String getName() { + return "VideoManager"; + } + + @ReactMethod + public void setPlayerStatus(Boolean shouldPlay, int reactTag) { + UIManagerModule uiManager = getReactApplicationContext().getNativeModule(UIManagerModule.class); + uiManager.prependUIBlock(manager -> { + View view = manager.resolveView(reactTag); + + if (view instanceof ReactExoplayerView) { + ReactExoplayerView videoView = (ReactExoplayerView) view; + videoView.setPausedModifier(!shouldPlay); + } + }); + } + + public VideoManagerModule(ReactApplicationContext reactContext) { + super(reactContext); + this.reactContext = reactContext; + } +} \ No newline at end of file