Compare commits
1 Commits
async-queu
...
railbird-v
| Author | SHA1 | Date | |
|---|---|---|---|
| 69a9159a43 |
@@ -34,6 +34,22 @@ enum RCTVideoAssetsUtils {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static func getDuration(asset: AVAsset) async -> CMTime? {
|
||||
if #available(iOS 15, tvOS 15, visionOS 1.0, *) {
|
||||
return try? await asset.load(.duration)
|
||||
} else {
|
||||
#if !os(visionOS)
|
||||
return await withCheckedContinuation { continuation in
|
||||
asset.loadValuesAsynchronously(forKeys: ["duration"]) {
|
||||
var error: NSError?
|
||||
let status = asset.statusOfValue(forKey: "duration", error: &error)
|
||||
continuation.resume(returning: status == .loaded ? asset.duration : nil)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - RCTVideoUtils
|
||||
|
||||
@@ -1420,7 +1420,10 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
}
|
||||
|
||||
if onVideoLoad != nil, self._videoLoadStarted {
|
||||
var duration = Float(CMTimeGetSeconds(_playerItem.asset.duration))
|
||||
let assetDuration = await RCTVideoAssetsUtils.getDuration(asset: _playerItem.asset)
|
||||
guard self._playerItem === _playerItem,
|
||||
self._source?.json === source.json else { return }
|
||||
var duration = Float(CMTimeGetSeconds(assetDuration ?? .invalid))
|
||||
|
||||
if duration.isNaN || duration == 0 {
|
||||
// This is a safety check for live video.
|
||||
@@ -1449,6 +1452,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
|
||||
let audioTracks = await RCTVideoUtils.getAudioTrackInfo(self._player)
|
||||
let textTracks = await RCTVideoUtils.getTextTrackInfo(self._player)
|
||||
guard self._playerItem === _playerItem,
|
||||
self._source?.json === source.json else { return }
|
||||
self.onVideoLoad?(["duration": NSNumber(value: duration),
|
||||
"currentTime": NSNumber(value: Float(CMTimeGetSeconds(_playerItem.currentTime()))),
|
||||
"canPlayReverse": NSNumber(value: _playerItem.canPlayReverse),
|
||||
@@ -1699,4 +1704,3 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
@objc
|
||||
func setOnClick(_: Any) {}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user