From 84a27f3d9f90624af3c5c3cbff50d754bab9baa4 Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Fri, 13 Sep 2024 10:50:33 +0200 Subject: [PATCH] fix: refactor side loaded text tracks management (#4158) * fix: refactor side loaded text tracks management More textTracks in source. android/ios: ensure text tracks are not selected by default android/ios make textTrack field not nullable clean up doc check compatibility with the old api Add comments on deprecated JS apis Apply API change on basic sample * chore: fix linter * fix(ios): fix build with caching & remove warnings --- .../common/api/SideLoadedTextTrackList.kt | 8 +- .../java/com/brentvatne/common/api/Source.kt | 10 +- .../common/toolbox/ReactBridgeUtils.kt | 12 +- .../exoplayer/ReactExoplayerView.java | 113 +++++++++--------- .../exoplayer/ReactExoplayerViewManager.kt | 9 -- docs/pages/component/props.mdx | 43 +++++++ examples/basic/src/VideoPlayer.tsx | 1 - .../SelectedTrackCriteria.swift | 4 + ios/Video/DataStructures/VideoSource.swift | 4 + ios/Video/RCTVideo.swift | 64 ++++------ ios/VideoCaching/RCTVideoCachingHandler.swift | 27 +++-- src/Video.tsx | 5 +- src/specs/VideoNativeComponent.ts | 2 +- src/types/video.ts | 8 +- 14 files changed, 179 insertions(+), 131 deletions(-) diff --git a/android/src/main/java/com/brentvatne/common/api/SideLoadedTextTrackList.kt b/android/src/main/java/com/brentvatne/common/api/SideLoadedTextTrackList.kt index e3d519c4..494facdc 100644 --- a/android/src/main/java/com/brentvatne/common/api/SideLoadedTextTrackList.kt +++ b/android/src/main/java/com/brentvatne/common/api/SideLoadedTextTrackList.kt @@ -11,12 +11,18 @@ import com.facebook.react.bridge.ReadableMap class SideLoadedTextTrackList { var tracks = ArrayList() + /** return true if this and src are equals */ + override fun equals(other: Any?): Boolean { + if (other == null || other !is SideLoadedTextTrackList) return false + return tracks == other.tracks + } + companion object { fun parse(src: ReadableArray?): SideLoadedTextTrackList? { if (src == null) { return null } - var sideLoadedTextTrackList = SideLoadedTextTrackList() + val sideLoadedTextTrackList = SideLoadedTextTrackList() for (i in 0 until src.size()) { val textTrack: ReadableMap = src.getMap(i) sideLoadedTextTrackList.tracks.add(SideLoadedTextTrack.parse(textTrack)) diff --git a/android/src/main/java/com/brentvatne/common/api/Source.kt b/android/src/main/java/com/brentvatne/common/api/Source.kt index b9ea8bf7..92fd9373 100644 --- a/android/src/main/java/com/brentvatne/common/api/Source.kt +++ b/android/src/main/java/com/brentvatne/common/api/Source.kt @@ -62,6 +62,11 @@ class Source { */ var cmcdProps: CMCDProps? = null + /** + * The list of sideLoaded text tracks + */ + var sideLoadedTextTracks: SideLoadedTextTrackList? = null + override fun hashCode(): Int = Objects.hash(uriString, uri, startPositionMs, cropStartMs, cropEndMs, extension, metadata, headers) /** return true if this and src are equals */ @@ -74,7 +79,8 @@ class Source { startPositionMs == other.startPositionMs && extension == other.extension && drmProps == other.drmProps && - cmcdProps == other.cmcdProps + cmcdProps == other.cmcdProps && + sideLoadedTextTracks == other.sideLoadedTextTracks ) } @@ -139,6 +145,7 @@ class Source { private const val PROP_SRC_DRM = "drm" private const val PROP_SRC_CMCD = "cmcd" private const val PROP_SRC_TEXT_TRACKS_ALLOW_CHUNKLESS_PREPARATION = "textTracksAllowChunklessPreparation" + private const val PROP_SRC_TEXT_TRACKS = "textTracks" @SuppressLint("DiscouragedApi") private fun getUriFromAssetId(context: Context, uriString: String): Uri? { @@ -198,6 +205,7 @@ class Source { source.drmProps = parse(safeGetMap(src, PROP_SRC_DRM)) source.cmcdProps = CMCDProps.parse(safeGetMap(src, PROP_SRC_CMCD)) source.textTracksAllowChunklessPreparation = safeGetBool(src, PROP_SRC_TEXT_TRACKS_ALLOW_CHUNKLESS_PREPARATION, true) + source.sideLoadedTextTracks = SideLoadedTextTrackList.parse(safeGetArray(src, PROP_SRC_TEXT_TRACKS)) val propSrcHeadersArray = safeGetArray(src, PROP_SRC_HEADERS) if (propSrcHeadersArray != null) { diff --git a/android/src/main/java/com/brentvatne/common/toolbox/ReactBridgeUtils.kt b/android/src/main/java/com/brentvatne/common/toolbox/ReactBridgeUtils.kt index 10f4752a..b4cce426 100644 --- a/android/src/main/java/com/brentvatne/common/toolbox/ReactBridgeUtils.kt +++ b/android/src/main/java/com/brentvatne/common/toolbox/ReactBridgeUtils.kt @@ -3,7 +3,6 @@ package com.brentvatne.common.toolbox import com.facebook.react.bridge.Dynamic import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap -import java.util.HashMap /* * Toolbox to safe parsing of