2022-05-19 07:29:25 -06:00
|
|
|
import AVFoundation
|
|
|
|
import React
|
|
|
|
|
|
|
|
@objc(RCTVideoManager)
|
|
|
|
class RCTVideoManager: RCTViewManager {
|
|
|
|
|
|
|
|
override func view() -> UIView {
|
2022-06-13 03:40:43 -06:00
|
|
|
return RCTVideo(eventDispatcher: bridge.eventDispatcher() as! RCTEventDispatcher)
|
2022-05-19 07:29:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func methodQueue() -> DispatchQueue {
|
|
|
|
return bridge.uiManager.methodQueue
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc(save:reactTag:resolver:rejecter:)
|
|
|
|
func save(options: NSDictionary, reactTag: NSNumber, resolve: @escaping RCTPromiseResolveBlock,reject: @escaping RCTPromiseRejectBlock) -> 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 {
|
|
|
|
view.save(options: options, resolve: resolve, reject: reject)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-05 13:37:28 -06:00
|
|
|
@objc(setLicenseResult:licenseUrl:reactTag:)
|
|
|
|
func setLicenseResult(license: NSString, licenseUrl:NSString, reactTag: NSNumber) -> Void {
|
2022-05-19 07:29:25 -06:00
|
|
|
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 {
|
2023-10-05 13:37:28 -06:00
|
|
|
view.setLicenseResult(license as String, licenseUrl as String)
|
2022-05-19 07:29:25 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-05 13:37:28 -06:00
|
|
|
@objc(setLicenseResultError:licenseUrl:reactTag:)
|
|
|
|
func setLicenseResultError(error: NSString, licenseUrl:NSString, reactTag: NSNumber) -> Void {
|
2022-05-19 07:29:25 -06:00
|
|
|
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 {
|
2023-10-05 13:37:28 -06:00
|
|
|
view.setLicenseResultError(error as String, licenseUrl as String)
|
2022-05-19 07:29:25 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-04 15:57:45 -06:00
|
|
|
@objc(dismissFullscreenPlayer:reactTag:)
|
|
|
|
func dismissFullscreenPlayer(error: NSString, 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 {
|
|
|
|
view.dismissFullscreenPlayer(error as String)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
@objc(presentFullscreenPlayer:reactTag:)
|
|
|
|
func presentFullscreenPlayer(error: NSString, 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 {
|
|
|
|
view.presentFullscreenPlayer(error as String)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-20 23:25:21 -06:00
|
|
|
@objc(setPlayerPauseState:reactTag:)
|
2023-09-22 01:04:20 -06:00
|
|
|
func setPlayerPauseState(paused: NSNumber, reactTag: NSNumber) -> Void {
|
2023-09-18 03:46:39 -06:00
|
|
|
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 {
|
2023-09-22 01:04:20 -06:00
|
|
|
let paused = paused.boolValue
|
|
|
|
view.setPaused(paused)
|
2023-09-18 03:46:39 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:29:25 -06:00
|
|
|
override func constantsToExport() -> [AnyHashable : Any]? {
|
|
|
|
return [
|
|
|
|
"ScaleNone": AVLayerVideoGravity.resizeAspect,
|
|
|
|
"ScaleToFill": AVLayerVideoGravity.resize,
|
|
|
|
"ScaleAspectFit": AVLayerVideoGravity.resizeAspect,
|
|
|
|
"ScaleAspectFill": AVLayerVideoGravity.resizeAspectFill
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
override class func requiresMainQueueSetup() -> Bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|