From 85c9e8f99083a0909d4e66890fea4183a3ea4871 Mon Sep 17 00:00:00 2001 From: KrzysztofMoch Date: Mon, 18 Sep 2023 11:46:39 +0200 Subject: [PATCH] feat(ios): add playback functions to ref --- Video.js | 16 ++++++++++++++-- ios/Video/RCTVideoManager.m | 3 +++ ios/Video/RCTVideoManager.swift | 13 +++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Video.js b/Video.js index 3d342d02..f29cd4d7 100644 --- a/Video.js +++ b/Video.js @@ -14,8 +14,8 @@ const styles = StyleSheet.create({ }, }); -const { VideoDecoderProperties } = NativeModules -export { TextTrackType, FilterType, DRMType, VideoDecoderProperties } +const { VideoDecoderProperties } = NativeModules; +export { TextTrackType, FilterType, DRMType, VideoDecoderProperties }; 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)); } + pause = async () => { + await this.setPlayerStatus(false); + }; + + play = async () => { + await this.setPlayerStatus(true); + }; + + setPlayerStatus = async (shouldPlay) => { + return await NativeModules.VideoManager.setPlayerStatus(shouldPlay, findNodeHandle(this._root)); + }; + restoreUserInterfaceForPictureInPictureStopCompleted = (restored) => { this.setNativeProps({ restoreUserInterfaceForPIPStopCompletionHandler: restored }); }; diff --git a/ios/Video/RCTVideoManager.m b/ios/Video/RCTVideoManager.m index 9bdf6101..83f49c4d 100644 --- a/ios/Video/RCTVideoManager.m +++ b/ios/Video/RCTVideoManager.m @@ -74,6 +74,9 @@ RCT_EXTERN_METHOD(setLicenseResult:(NSString *)license RCT_EXTERN_METHOD(setLicenseResultError(NSString *)error reactTag:(nonnull NSNumber *)reactTag) +RCT_EXTERN_METHOD(setPlayerStatus:(nonnull NSNumber *)shouldPlay + reactTag:(nonnull NSNumber *)reactTag) + RCT_EXTERN_METHOD(presentFullscreenPlayer reactTag:(nonnull NSNumber *)reactTag) diff --git a/ios/Video/RCTVideoManager.swift b/ios/Video/RCTVideoManager.swift index bfdec7a4..3e118d3c 100644 --- a/ios/Video/RCTVideoManager.swift +++ b/ios/Video/RCTVideoManager.swift @@ -71,6 +71,19 @@ class RCTVideoManager: RCTViewManager { }) } + @objc(setPlayerStatus:reactTag:) + func setPlayerStatus(shouldPlay: 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 shouldPlay = shouldPlay.boolValue + view.setPaused(!shouldPlay) + } + }) + } + override func constantsToExport() -> [AnyHashable : Any]? { return [ "ScaleNone": AVLayerVideoGravity.resizeAspect,