@takeoffmedia/react-native-penthera 0.8.7 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/android/src/main/java/com/takeoffmediareactnativepenthera/virtuoso/OfflineVideoEngine.kt
CHANGED
|
@@ -4,7 +4,7 @@ import android.annotation.SuppressLint
|
|
|
4
4
|
import android.content.Context
|
|
5
5
|
import android.util.Log
|
|
6
6
|
import com.bitmovin.player.api.media.subtitle.SubtitleTrack
|
|
7
|
-
import com.bitmovin.player.reactnative.
|
|
7
|
+
import com.bitmovin.player.reactnative.PlayerRegistry
|
|
8
8
|
import com.facebook.react.bridge.Arguments
|
|
9
9
|
import com.facebook.react.bridge.Promise
|
|
10
10
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
@@ -135,16 +135,23 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
|
|
|
135
135
|
for (i in 0 until subtitles.length()) {
|
|
136
136
|
val subtitle = subtitles.getJSONObject(i)
|
|
137
137
|
val language = subtitle["language"] as String
|
|
138
|
-
val href = subtitle
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
URL(href
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
val href = subtitle.optString("href", "").trim()
|
|
139
|
+
if (href.isNotBlank() && !href.equals("null", ignoreCase = true)) {
|
|
140
|
+
try {
|
|
141
|
+
val subtitleUrl = URL(href)
|
|
142
|
+
fileList.add(
|
|
143
|
+
AncillaryFile(
|
|
144
|
+
subtitleUrl,
|
|
145
|
+
language,
|
|
146
|
+
arrayOf(language),
|
|
147
|
+
language,
|
|
148
|
+
subtitleUrl
|
|
149
|
+
)
|
|
150
|
+
)
|
|
151
|
+
} catch (e: MalformedURLException) {
|
|
152
|
+
Log.w("Penthera", "Skipping invalid subtitle URL: $href", e)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
148
155
|
}
|
|
149
156
|
|
|
150
157
|
val params = MPDAssetBuilder().apply {
|
|
@@ -426,12 +433,11 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
|
|
|
426
433
|
virtuoso.assetManager.getByAssetId(assetId)?.firstOrNull()?.let { asset ->
|
|
427
434
|
val sourceManager = BitmovinSourceManager(context, asset as ISegmentedAsset)
|
|
428
435
|
val sourceItem = sourceManager.bitmovinSourceItem
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
var player = playerModule.getPlayerOrNull(nativeId)
|
|
436
|
+
if (sourceItem != null) {
|
|
437
|
+
var player = PlayerRegistry.getPlayer(nativeId)
|
|
432
438
|
while (player == null) {
|
|
433
439
|
Thread.sleep(100)
|
|
434
|
-
player =
|
|
440
|
+
player = PlayerRegistry.getPlayer(nativeId)
|
|
435
441
|
}
|
|
436
442
|
val metadata = JSONObject(asset.metadata)
|
|
437
443
|
val subtitles = JSONArray(metadata["subtitles"] as String)
|
|
@@ -487,7 +493,7 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
|
|
|
487
493
|
}
|
|
488
494
|
|
|
489
495
|
sourceItem.metadata = metaDataMap
|
|
490
|
-
player
|
|
496
|
+
player?.load(sourceItem)
|
|
491
497
|
promise.resolve(true)
|
|
492
498
|
}
|
|
493
499
|
}
|