2022-05-19 07:29:25 -06:00
|
|
|
import AVFoundation
|
|
|
|
import React
|
|
|
|
|
|
|
|
@objc(RCTVideoManager)
|
|
|
|
class RCTVideoManager: RCTViewManager {
|
|
|
|
override func view() -> UIView {
|
2024-03-07 12:16:11 -07:00
|
|
|
return RCTVideo(eventDispatcher: (RCTBridge.current().eventDispatcher() as! RCTEventDispatcher))
|
2022-05-19 07:29:25 -06:00
|
|
|
}
|
2023-12-07 00:47:40 -07:00
|
|
|
|
2022-05-19 07:29:25 -06:00
|
|
|
func methodQueue() -> DispatchQueue {
|
|
|
|
return bridge.uiManager.methodQueue
|
|
|
|
}
|
2023-12-07 00:47:40 -07:00
|
|
|
|
2024-03-28 04:22:04 -06:00
|
|
|
func performOnVideoView(withReactTag reactTag: NSNumber, callback: @escaping (RCTVideo?) -> Void) {
|
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
|
guard let self else {
|
|
|
|
callback(nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-27 01:22:22 -06:00
|
|
|
let view = self.bridge.uiManager.view(forReactTag: reactTag)
|
|
|
|
|
|
|
|
guard let videoView = view as? RCTVideo else {
|
2024-06-07 06:04:00 -06:00
|
|
|
DebugLog("Invalid view returned from registry, expecting RCTVideo, got: \(String(describing: self.view))")
|
2024-03-28 04:22:04 -06:00
|
|
|
callback(nil)
|
|
|
|
return
|
2022-05-19 07:29:25 -06:00
|
|
|
}
|
2024-03-28 04:22:04 -06:00
|
|
|
|
2024-05-27 01:22:22 -06:00
|
|
|
callback(videoView)
|
2023-12-07 00:47:40 -07:00
|
|
|
}
|
2022-05-19 07:29:25 -06:00
|
|
|
}
|
2023-12-07 00:47:40 -07:00
|
|
|
|
2024-03-28 04:22:04 -06:00
|
|
|
@objc(save:reactTag:resolver:rejecter:)
|
|
|
|
func save(options: NSDictionary, reactTag: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
|
|
|
videoView?.save(options: options, resolve: resolve, reject: reject)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(seek:reactTag:)
|
|
|
|
func seek(info: NSDictionary, reactTag: NSNumber) {
|
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
|
|
|
videoView?.setSeek(info)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-05 13:37:28 -06:00
|
|
|
@objc(setLicenseResult:licenseUrl:reactTag:)
|
2023-12-07 00:47:40 -07:00
|
|
|
func setLicenseResult(license: NSString, licenseUrl: NSString, reactTag: NSNumber) {
|
2024-03-28 04:22:04 -06:00
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
|
|
|
videoView?.setLicenseResult(license as String, licenseUrl as String)
|
|
|
|
})
|
2022-05-19 07:29:25 -06:00
|
|
|
}
|
2023-12-07 00:47:40 -07:00
|
|
|
|
2023-10-05 13:37:28 -06:00
|
|
|
@objc(setLicenseResultError:licenseUrl:reactTag:)
|
2023-12-07 00:47:40 -07:00
|
|
|
func setLicenseResultError(error: NSString, licenseUrl: NSString, reactTag: NSNumber) {
|
2024-03-28 04:22:04 -06:00
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
|
|
|
videoView?.setLicenseResultError(error as String, licenseUrl as String)
|
|
|
|
})
|
2022-05-19 07:29:25 -06:00
|
|
|
}
|
2023-12-07 00:47:40 -07:00
|
|
|
|
2023-11-08 11:04:39 -07:00
|
|
|
@objc(dismissFullscreenPlayer:)
|
2023-12-07 00:47:40 -07:00
|
|
|
func dismissFullscreenPlayer(_ reactTag: NSNumber) {
|
2024-03-28 04:22:04 -06:00
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
|
|
|
videoView?.dismissFullscreenPlayer()
|
|
|
|
})
|
2023-09-04 15:57:45 -06:00
|
|
|
}
|
2023-12-07 00:47:40 -07:00
|
|
|
|
2023-11-08 11:04:39 -07:00
|
|
|
@objc(presentFullscreenPlayer:)
|
2023-12-07 00:47:40 -07:00
|
|
|
func presentFullscreenPlayer(_ reactTag: NSNumber) {
|
2024-03-28 04:22:04 -06:00
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
|
|
|
videoView?.presentFullscreenPlayer()
|
|
|
|
})
|
2023-09-04 15:57:45 -06:00
|
|
|
}
|
|
|
|
|
2023-09-20 23:25:21 -06:00
|
|
|
@objc(setPlayerPauseState:reactTag:)
|
2023-12-07 00:47:40 -07:00
|
|
|
func setPlayerPauseState(paused: NSNumber, reactTag: NSNumber) {
|
2024-03-28 04:22:04 -06:00
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
|
|
|
videoView?.setPaused(paused.boolValue)
|
|
|
|
})
|
2023-09-18 03:46:39 -06:00
|
|
|
}
|
|
|
|
|
2024-05-20 04:21:48 -06:00
|
|
|
@objc(setVolume:reactTag:)
|
|
|
|
func setVolume(value: Float, reactTag: NSNumber) {
|
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
|
|
|
videoView?.setVolume(value)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-28 03:00:38 -06:00
|
|
|
@objc(getCurrentPosition:resolver:rejecter:)
|
|
|
|
func getCurrentPosition(reactTag: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
|
|
|
videoView?.getCurrentPlaybackTime(resolve, reject)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-10 14:41:26 -06:00
|
|
|
@objc(setFullScreen:reactTag:)
|
|
|
|
func setFullScreen(fullScreen: Bool, reactTag: NSNumber) {
|
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
|
|
|
videoView?.setFullscreen(fullScreen)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:29:25 -06:00
|
|
|
override class func requiresMainQueueSetup() -> Bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|