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
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let view = self.bridge.uiManager.view(forReactTag: reactTag) as? RCTVideo else {
|
|
|
|
RCTLogError("Invalid view returned from registry, expecting RCTVideo, got: \(String(describing: view))")
|
|
|
|
callback(nil)
|
|
|
|
return
|
2022-05-19 07:29:25 -06:00
|
|
|
}
|
2024-03-28 04:22:04 -06:00
|
|
|
|
|
|
|
callback(view)
|
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
|
|
|
}
|
|
|
|
|
2022-05-19 07:29:25 -06:00
|
|
|
override class func requiresMainQueueSetup() -> Bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|