feat(android): add playback functions to ref

This commit is contained in:
KrzysztofMoch 2023-09-18 13:09:53 +02:00
parent 85c9e8f990
commit 0066ec744c
3 changed files with 47 additions and 4 deletions

View File

@ -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,

View File

@ -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<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Collections.singletonList(
new VideoDecoderPropertiesModule(reactContext)
);
List<NativeModule> modules = new ArrayList<NativeModule>();
modules.add(new VideoDecoderPropertiesModule(reactContext));
modules.add(new VideoManagerModule(reactContext));
return modules;
}
// Deprecated RN 0.47

View File

@ -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;
}
}