Compare commits
5 Commits
async-queu
...
loewy/fix-
| Author | SHA1 | Date | |
|---|---|---|---|
| dfe2957087 | |||
| d7563cfd93 | |||
| 69a9159a43 | |||
| c6bd3e3ee4 | |||
| 2d953c4c46 |
@@ -24,7 +24,7 @@ class SideLoadedTextTrackList {
|
|||||||
}
|
}
|
||||||
val sideLoadedTextTrackList = SideLoadedTextTrackList()
|
val sideLoadedTextTrackList = SideLoadedTextTrackList()
|
||||||
for (i in 0 until src.size()) {
|
for (i in 0 until src.size()) {
|
||||||
val textTrack: ReadableMap = src.getMap(i)
|
val textTrack: ReadableMap = src.getMap(i) ?: continue
|
||||||
sideLoadedTextTrackList.tracks.add(SideLoadedTextTrack.parse(textTrack))
|
sideLoadedTextTrackList.tracks.add(SideLoadedTextTrack.parse(textTrack))
|
||||||
}
|
}
|
||||||
return sideLoadedTextTrackList
|
return sideLoadedTextTrackList
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ class Source {
|
|||||||
if (propSrcHeadersArray != null) {
|
if (propSrcHeadersArray != null) {
|
||||||
if (propSrcHeadersArray.size() > 0) {
|
if (propSrcHeadersArray.size() > 0) {
|
||||||
for (i in 0 until propSrcHeadersArray.size()) {
|
for (i in 0 until propSrcHeadersArray.size()) {
|
||||||
val current = propSrcHeadersArray.getMap(i)
|
val current = propSrcHeadersArray.getMap(i) ?: continue
|
||||||
val key = if (current.hasKey("key")) current.getString("key") else null
|
val key = if (current.hasKey("key")) current.getString("key") else null
|
||||||
val value = if (current.hasKey("value")) current.getString("value") else null
|
val value = if (current.hasKey("value")) current.getString("value") else null
|
||||||
if (key != null && value != null) {
|
if (key != null && value != null) {
|
||||||
|
|||||||
@@ -288,12 +288,22 @@ class VideoEventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class VideoEvent(
|
||||||
|
surfaceId: Int,
|
||||||
|
viewId: Int,
|
||||||
|
private val name: String,
|
||||||
|
private val data: WritableMap?
|
||||||
|
) : Event<VideoEvent>(surfaceId, viewId) {
|
||||||
|
override fun getEventName() = name
|
||||||
|
override fun getEventData() = data
|
||||||
|
}
|
||||||
|
|
||||||
private class EventBuilder(private val surfaceId: Int, private val viewId: Int, private val dispatcher: EventDispatcher) {
|
private class EventBuilder(private val surfaceId: Int, private val viewId: Int, private val dispatcher: EventDispatcher) {
|
||||||
fun dispatch(event: EventTypes, paramsSetter: (WritableMap.() -> Unit)? = null) =
|
fun dispatch(event: EventTypes, paramsSetter: (WritableMap.() -> Unit)? = null) {
|
||||||
dispatcher.dispatchEvent(object : Event<Event<*>>(surfaceId, viewId) {
|
val eventName = "top${event.eventName.removePrefix("on")}"
|
||||||
override fun getEventName() = "top${event.eventName.removePrefix("on")}"
|
val eventData = Arguments.createMap().apply(paramsSetter ?: {})
|
||||||
override fun getEventData() = Arguments.createMap().apply(paramsSetter ?: {})
|
dispatcher.dispatchEvent(VideoEvent(surfaceId, viewId, eventName, eventData))
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun audioTracksToArray(audioTracks: java.util.ArrayList<Track>?): WritableArray =
|
private fun audioTracksToArray(audioTracks: java.util.ArrayList<Track>?): WritableArray =
|
||||||
|
|||||||
@@ -34,6 +34,22 @@ enum RCTVideoAssetsUtils {
|
|||||||
#endif
|
#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
|
// MARK: - RCTVideoUtils
|
||||||
|
|||||||
@@ -1420,7 +1420,10 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
if onVideoLoad != nil, self._videoLoadStarted {
|
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 {
|
if duration.isNaN || duration == 0 {
|
||||||
// This is a safety check for live video.
|
// 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 audioTracks = await RCTVideoUtils.getAudioTrackInfo(self._player)
|
||||||
let textTracks = await RCTVideoUtils.getTextTrackInfo(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),
|
self.onVideoLoad?(["duration": NSNumber(value: duration),
|
||||||
"currentTime": NSNumber(value: Float(CMTimeGetSeconds(_playerItem.currentTime()))),
|
"currentTime": NSNumber(value: Float(CMTimeGetSeconds(_playerItem.currentTime()))),
|
||||||
"canPlayReverse": NSNumber(value: _playerItem.canPlayReverse),
|
"canPlayReverse": NSNumber(value: _playerItem.canPlayReverse),
|
||||||
@@ -1699,4 +1704,3 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
@objc
|
@objc
|
||||||
func setOnClick(_: Any) {}
|
func setOnClick(_: Any) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,13 @@ import React
|
|||||||
@objc(RCTVideoManager)
|
@objc(RCTVideoManager)
|
||||||
class RCTVideoManager: RCTViewManager {
|
class RCTVideoManager: RCTViewManager {
|
||||||
override func view() -> UIView {
|
override func view() -> UIView {
|
||||||
return RCTVideo(eventDispatcher: (RCTBridge.current().eventDispatcher() as! RCTEventDispatcher))
|
// `RCTBridge.current()` returns nil under bridgeless (New Architecture), and it
|
||||||
|
// is nonnull-annotated, so Swift emits an unconditional nil-check trap around
|
||||||
|
// the call -- optional chaining does not avoid it. Every <Video> mount killed
|
||||||
|
// the app. RCTVideo only stores this dispatcher and never reads it (events go
|
||||||
|
// out through the RCT_EXPORT_VIEW_PROPERTY direct event blocks), so skip the
|
||||||
|
// lookup entirely.
|
||||||
|
return RCTVideo(eventDispatcher: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func methodQueue() -> DispatchQueue {
|
func methodQueue() -> DispatchQueue {
|
||||||
|
|||||||
@@ -32,17 +32,18 @@
|
|||||||
"react-native": "0.73.2",
|
"react-native": "0.73.2",
|
||||||
"react-native-windows": "^0.61.0-0",
|
"react-native-windows": "^0.61.0-0",
|
||||||
"release-it": "^16.2.1",
|
"release-it": "^16.2.1",
|
||||||
"typescript": "5.1.6",
|
|
||||||
"patch-package": "^8.0.0"
|
"patch-package": "^8.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"shaka-player": "^4.11.7"
|
"shaka-player": "^4.11.7",
|
||||||
|
"typescript": "5.6.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"react": "*",
|
"react": "*",
|
||||||
"react-native": "*"
|
"react-native": "*"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"install": "tsc --noCheck",
|
||||||
"lint": "yarn eslint .",
|
"lint": "yarn eslint .",
|
||||||
"build": "yarn tsc",
|
"build": "yarn tsc",
|
||||||
"prepare": "yarn build",
|
"prepare": "yarn build",
|
||||||
@@ -61,6 +62,8 @@
|
|||||||
"windows",
|
"windows",
|
||||||
"src",
|
"src",
|
||||||
"lib",
|
"lib",
|
||||||
|
"tsconfig.json",
|
||||||
|
"tsconfig.build.json",
|
||||||
"react-native-video.podspec",
|
"react-native-video.podspec",
|
||||||
"app.plugin.js",
|
"app.plugin.js",
|
||||||
"!android/build",
|
"!android/build",
|
||||||
|
|||||||
@@ -734,7 +734,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
|
|
||||||
// poster style
|
// poster style
|
||||||
const baseStyle: StyleProp<ImageStyle> = {
|
const baseStyle: StyleProp<ImageStyle> = {
|
||||||
...StyleSheet.absoluteFillObject,
|
...StyleSheet.absoluteFill,
|
||||||
resizeMode: _posterResizeMode,
|
resizeMode: _posterResizeMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -787,7 +787,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
|
|
||||||
const _style: StyleProp<ViewStyle> = useMemo(
|
const _style: StyleProp<ViewStyle> = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
...StyleSheet.absoluteFillObject,
|
...StyleSheet.absoluteFill,
|
||||||
...(showPoster ? {display: 'none'} : {}),
|
...(showPoster ? {display: 'none'} : {}),
|
||||||
}),
|
}),
|
||||||
[showPoster],
|
[showPoster],
|
||||||
|
|||||||
@@ -515,7 +515,9 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
const videoStyle = {
|
const videoStyle = {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
inset: 0,
|
inset: 0,
|
||||||
objectFit: 'contain',
|
// Use 'fill' instead of 'contain' to force video to match container dimensions.
|
||||||
|
// This works around browsers miscalculating intrinsic dimensions from rotation matrices.
|
||||||
|
objectFit: 'fill',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
} satisfies React.CSSProperties;
|
} satisfies React.CSSProperties;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"extends": "./tsconfig",
|
"extends": "./tsconfig",
|
||||||
"exclude": ["examples", "lib"]
|
"exclude": ["examples", "lib"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
"lib": ["esnext"],
|
"lib": ["esnext"],
|
||||||
"module": "CommonJS",
|
"module": "Node16",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "Node16",
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
"noImplicitUseStrict": false,
|
"noImplicitUseStrict": false,
|
||||||
|
|||||||
Reference in New Issue
Block a user