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
|
|
|
|
2022-05-19 07:29:25 -06:00
|
|
|
@objc(save:reactTag:resolver:rejecter:)
|
2023-12-07 00:47:40 -07:00
|
|
|
func save(options: NSDictionary, reactTag: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
|
|
bridge.uiManager.prependUIBlock { _, viewRegistry in
|
2022-05-19 07:29:25 -06:00
|
|
|
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-12-07 00:47:40 -07:00
|
|
|
}
|
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(setLicenseResult:licenseUrl:reactTag:)
|
2023-12-07 00:47:40 -07:00
|
|
|
func setLicenseResult(license: NSString, licenseUrl: NSString, reactTag: NSNumber) {
|
|
|
|
bridge.uiManager.prependUIBlock { _, viewRegistry in
|
2022-05-19 07:29:25 -06:00
|
|
|
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-12-07 00:47:40 -07:00
|
|
|
}
|
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) {
|
|
|
|
bridge.uiManager.prependUIBlock { _, viewRegistry in
|
2022-05-19 07:29:25 -06:00
|
|
|
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-12-07 00:47:40 -07:00
|
|
|
}
|
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) {
|
|
|
|
bridge.uiManager.prependUIBlock { _, viewRegistry in
|
2023-09-04 15:57:45 -06:00
|
|
|
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-11-08 11:04:39 -07:00
|
|
|
view.dismissFullscreenPlayer()
|
2023-09-04 15:57:45 -06:00
|
|
|
}
|
2023-12-07 00:47:40 -07:00
|
|
|
}
|
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) {
|
|
|
|
bridge.uiManager.prependUIBlock { _, viewRegistry in
|
2023-09-04 15:57:45 -06:00
|
|
|
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-11-08 11:04:39 -07:00
|
|
|
view.presentFullscreenPlayer()
|
2023-09-04 15:57:45 -06:00
|
|
|
}
|
2023-12-07 00:47:40 -07:00
|
|
|
}
|
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) {
|
|
|
|
bridge.uiManager.prependUIBlock { _, viewRegistry in
|
2023-09-18 03:46:39 -06:00
|
|
|
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
|
|
|
}
|
2023-12-07 00:47:40 -07:00
|
|
|
}
|
2023-09-18 03:46:39 -06:00
|
|
|
}
|
|
|
|
|
2022-05-19 07:29:25 -06:00
|
|
|
override class func requiresMainQueueSetup() -> Bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|