Merge pull request #3245 from TheWidlarzGroup/feat/playback-ref-functions

feat: expose playback functions
This commit is contained in:
Olivier Bouillet 2023-09-30 09:28:49 +02:00 committed by GitHub
commit c6ee294403
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 102 additions and 6 deletions

24
API.md
View File

@ -1645,6 +1645,30 @@ this.player.seek(120, 50); // Seek to 2 minutes with +/- 50 milliseconds accurac
Platforms: iOS Platforms: iOS
### pause
`pause(): Promise<void>`
Pause the video.
Example:
```
this.player.pause();
```
Platforms: Android, iOS
### play
`play(): Promise<void>`
Play the video.
Example:
```
this.player.play();
```
Platforms: Android, iOS
#### Static methods #### Static methods
### Video Decoding capabilities ### Video Decoding capabilities

View File

@ -1,6 +1,7 @@
## Changelog ## Changelog
## Next ## Next
- iOS, Android: expose playback functions to ref [#3245](https://github.com/react-native-video/react-native-video/pull/3245)
- Windows: fix build error from over-specified SDK version [#3246](https://github.com/react-native-video/react-native-video/pull/3246) - Windows: fix build error from over-specified SDK version [#3246](https://github.com/react-native-video/react-native-video/pull/3246)
- Windows: fix `onError` not being raised [#3247](https://github.com/react-native-video/react-native-video/pull/3247) - Windows: fix `onError` not being raised [#3247](https://github.com/react-native-video/react-native-video/pull/3247)
- **BREAKING CHANGE**Android: update isCodecSupported to return enum [#3254](https://github.com/react-native-video/react-native-video/pull/3254) - **BREAKING CHANGE**Android: update isCodecSupported to return enum [#3254](https://github.com/react-native-video/react-native-video/pull/3254)

View File

@ -14,8 +14,8 @@ const styles = StyleSheet.create({
}, },
}); });
const { VideoDecoderProperties } = NativeModules const { VideoDecoderProperties } = NativeModules;
export { TextTrackType, FilterType, DRMType, VideoDecoderProperties } export { TextTrackType, FilterType, DRMType, VideoDecoderProperties };
export default class Video extends Component { export default class Video extends Component {
@ -81,6 +81,18 @@ export default class Video extends Component {
return await NativeModules.VideoManager.save(options, findNodeHandle(this._root)); return await NativeModules.VideoManager.save(options, findNodeHandle(this._root));
} }
pause = async () => {
await this.setPlayerPauseState(true);
};
play = async () => {
await this.setPlayerPauseState(false);
};
setPlayerPauseState = async (paused) => {
return await NativeModules.VideoManager.setPlayerPauseState(paused, findNodeHandle(this._root));
};
restoreUserInterfaceForPictureInPictureStopCompleted = (restored) => { restoreUserInterfaceForPictureInPictureStopCompleted = (restored) => {
this.setNativeProps({ restoreUserInterfaceForPIPStopCompletionHandler: restored }); this.setNativeProps({ restoreUserInterfaceForPIPStopCompletionHandler: restored });
}; };

View File

@ -116,7 +116,7 @@ import java.util.concurrent.TimeUnit;
import java.lang.Integer; import java.lang.Integer;
@SuppressLint("ViewConstructor") @SuppressLint("ViewConstructor")
class ReactExoplayerView extends FrameLayout implements public class ReactExoplayerView extends FrameLayout implements
LifecycleEventListener, LifecycleEventListener,
Player.Listener, Player.Listener,
BandwidthMeter.EventListener, BandwidthMeter.EventListener,

View File

@ -9,6 +9,7 @@ import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -25,9 +26,12 @@ public class ReactVideoPackage implements ReactPackage {
@Override @Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Collections.singletonList( List<NativeModule> modules = new ArrayList<NativeModule>();
new VideoDecoderPropertiesModule(reactContext)
); modules.add(new VideoDecoderPropertiesModule(reactContext));
modules.add(new VideoManagerModule(reactContext));
return modules;
} }
// Deprecated RN 0.47 // 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 setPlayerPauseState(Boolean paused, 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(paused);
}
});
}
public VideoManagerModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}
}

View File

@ -74,6 +74,9 @@ RCT_EXTERN_METHOD(setLicenseResult:(NSString *)license
RCT_EXTERN_METHOD(setLicenseResultError(NSString *)error RCT_EXTERN_METHOD(setLicenseResultError(NSString *)error
reactTag:(nonnull NSNumber *)reactTag) reactTag:(nonnull NSNumber *)reactTag)
RCT_EXTERN_METHOD(setPlayerPauseState:(nonnull NSNumber *)paused
reactTag:(nonnull NSNumber *)reactTag)
RCT_EXTERN_METHOD(presentFullscreenPlayer RCT_EXTERN_METHOD(presentFullscreenPlayer
reactTag:(nonnull NSNumber *)reactTag) reactTag:(nonnull NSNumber *)reactTag)

View File

@ -71,6 +71,19 @@ class RCTVideoManager: RCTViewManager {
}) })
} }
@objc(setPlayerPauseState:reactTag:)
func setPlayerPauseState(paused: NSNumber, reactTag: NSNumber) -> Void {
bridge.uiManager.prependUIBlock({_ , viewRegistry in
let view = viewRegistry?[reactTag]
if !(view is RCTVideo) {
RCTLogError("Invalid view returned from registry, expecting RCTVideo, got: %@", String(describing: view))
} else if let view = view as? RCTVideo {
let paused = paused.boolValue
view.setPaused(paused)
}
})
}
override func constantsToExport() -> [AnyHashable : Any]? { override func constantsToExport() -> [AnyHashable : Any]? {
return [ return [
"ScaleNone": AVLayerVideoGravity.resizeAspect, "ScaleNone": AVLayerVideoGravity.resizeAspect,