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-07-12 02:27:42 -06:00
|
|
|
@objc(seekCmd:time:tolerance:)
|
|
|
|
func seekCmd(_ reactTag: NSNumber, time: NSNumber, tolerance: NSNumber) {
|
2024-03-28 04:22:04 -06:00
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
2024-07-12 02:27:42 -06:00
|
|
|
videoView?.setSeek(time, tolerance)
|
2024-03-28 04:22:04 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-07-12 02:27:42 -06:00
|
|
|
@objc(setLicenseResultCmd:license:licenseUrl:)
|
|
|
|
func setLicenseResultCmd(_ reactTag: NSNumber, license: NSString, licenseUrl: NSString) {
|
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
|
|
|
|
2024-07-12 02:27:42 -06:00
|
|
|
@objc(setLicenseResultErrorCmd:error:licenseUrl:)
|
|
|
|
func setLicenseResultErrorCmd(_ reactTag: NSNumber, error: NSString, licenseUrl: NSString) {
|
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
|
|
|
|
2024-07-12 02:27:42 -06:00
|
|
|
@objc(setPlayerPauseStateCmd:paused:)
|
|
|
|
func setPlayerPauseStateCmd(_ reactTag: NSNumber, paused: Bool) {
|
2024-03-28 04:22:04 -06:00
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
2024-07-12 02:27:42 -06:00
|
|
|
videoView?.setPaused(paused)
|
2024-03-28 04:22:04 -06:00
|
|
|
})
|
2023-09-04 15:57:45 -06:00
|
|
|
}
|
2023-12-07 00:47:40 -07:00
|
|
|
|
2024-07-12 02:27:42 -06:00
|
|
|
@objc(setVolumeCmd:volume:)
|
|
|
|
func setVolumeCmd(_ reactTag: NSNumber, volume: Float) {
|
2024-03-28 04:22:04 -06:00
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
2024-07-12 02:27:42 -06:00
|
|
|
videoView?.setVolume(volume)
|
2024-03-28 04:22:04 -06:00
|
|
|
})
|
2023-09-04 15:57:45 -06:00
|
|
|
}
|
|
|
|
|
2024-07-12 02:27:42 -06:00
|
|
|
@objc(setFullScreenCmd:fullscreen:)
|
|
|
|
func setFullScreenCmd(_ reactTag: NSNumber, fullScreen: Bool) {
|
2024-03-28 04:22:04 -06:00
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
2024-07-12 02:27:42 -06:00
|
|
|
videoView?.setFullscreen(fullScreen)
|
2024-03-28 04:22:04 -06:00
|
|
|
})
|
2023-09-18 03:46:39 -06:00
|
|
|
}
|
|
|
|
|
2024-10-10 14:59:41 -06:00
|
|
|
@objc(setSourceCmd:source:)
|
|
|
|
func setSourceCmd(_ reactTag: NSNumber, source: NSDictionary) {
|
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
|
|
|
videoView?.setSrc(source)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-07-12 02:27:42 -06:00
|
|
|
@objc(save:options:resolve:reject:)
|
|
|
|
func save(_ reactTag: NSNumber, options: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
2024-05-20 04:21:48 -06:00
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
2024-07-12 02:27:42 -06:00
|
|
|
videoView?.save(options, resolve, reject)
|
2024-05-20 04:21:48 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-07-12 02:27:42 -06:00
|
|
|
@objc(getCurrentPosition:resolve:reject:)
|
|
|
|
func getCurrentPosition(_ reactTag: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
2024-05-28 03:00:38 -06:00
|
|
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
|
|
|
videoView?.getCurrentPlaybackTime(resolve, reject)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:29:25 -06:00
|
|
|
override class func requiresMainQueueSetup() -> Bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|