@takeoffmedia/react-native-penthera 0.9.0 → 0.9.1
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
|
@@ -338,40 +338,58 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
|
|
|
338
338
|
}
|
|
339
339
|
|
|
340
340
|
|
|
341
|
+
private fun buildGetByAssetIdPayload(asset: VirtuosoSegmentedFile): String {
|
|
342
|
+
val keyValueMap = HashMap<String, Any>()
|
|
343
|
+
keyValueMap["offlineUrl"] = asset.playbackURL?.toString() ?: ""
|
|
344
|
+
keyValueMap["metadata"] = asset.metadata.toString()
|
|
345
|
+
|
|
346
|
+
val ancillaryFiles = try {
|
|
347
|
+
(asset as ISegmentedAsset).getAncillaryFiles(context)
|
|
348
|
+
} catch (e: Exception) {
|
|
349
|
+
Log.w("Penthera", "getByAssetId: ancillary files unavailable for ${asset.assetId}", e)
|
|
350
|
+
emptyList<Any>()
|
|
351
|
+
}
|
|
352
|
+
keyValueMap["ancillary"] = ancillaryFiles
|
|
353
|
+
|
|
354
|
+
return gson.toJson(keyValueMap)
|
|
355
|
+
}
|
|
356
|
+
|
|
341
357
|
fun getByAssetId(assetId: String): String? {
|
|
342
358
|
return Util.retryWithDelay(maxRetries = 5, delayMillis = 1000) {
|
|
343
359
|
val list: MutableList<IIdentifier> = virtuoso.assetManager.getByAssetId(assetId)
|
|
344
360
|
if (list.isNotEmpty()) {
|
|
345
361
|
val asset = list[0] as VirtuosoSegmentedFile
|
|
362
|
+
val payload = buildGetByAssetIdPayload(asset)
|
|
346
363
|
|
|
347
|
-
//
|
|
348
|
-
val offlineUrl = asset.playbackURL
|
|
349
|
-
if (offlineUrl
|
|
364
|
+
// Optional local manifest probe: this must not block offline playback
|
|
365
|
+
val offlineUrl = asset.playbackURL?.toString()
|
|
366
|
+
if (!offlineUrl.isNullOrBlank()) {
|
|
350
367
|
val request = Request.Builder()
|
|
351
|
-
.url(offlineUrl
|
|
368
|
+
.url(offlineUrl)
|
|
352
369
|
.build()
|
|
353
370
|
|
|
354
371
|
try {
|
|
355
372
|
client.newCall(request).execute().use { response ->
|
|
356
|
-
if (!response.isSuccessful)
|
|
373
|
+
if (!response.isSuccessful) {
|
|
374
|
+
Log.w(
|
|
375
|
+
"Penthera",
|
|
376
|
+
"getByAssetId: offlineUrl probe failed (${response.code}) for assetId=$assetId"
|
|
377
|
+
)
|
|
378
|
+
}
|
|
357
379
|
}
|
|
358
|
-
|
|
359
|
-
val keyValueMap = HashMap<String, Any>()
|
|
360
|
-
keyValueMap["offlineUrl"] = offlineUrl.toString()
|
|
361
|
-
keyValueMap["metadata"] = asset.metadata.toString()
|
|
362
|
-
|
|
363
|
-
val ancillaryFiles = (asset as ISegmentedAsset).getAncillaryFiles(context)
|
|
364
|
-
|
|
365
|
-
// HERE THE ASSET MANIFEST IS REQUESTED
|
|
366
|
-
keyValueMap["ancillary"] = ancillaryFiles
|
|
367
|
-
return@retryWithDelay gson.toJson(keyValueMap)
|
|
368
380
|
} catch (e: IOException) {
|
|
369
|
-
|
|
381
|
+
Log.w(
|
|
382
|
+
"Penthera",
|
|
383
|
+
"getByAssetId: offlineUrl probe failed, continuing with local payload",
|
|
384
|
+
e
|
|
385
|
+
)
|
|
370
386
|
}
|
|
371
387
|
} else {
|
|
372
|
-
|
|
373
|
-
println("Error: offlineUrl is null")
|
|
388
|
+
Log.w("Penthera", "getByAssetId: offlineUrl is null/blank for assetId=$assetId")
|
|
374
389
|
}
|
|
390
|
+
|
|
391
|
+
// Always return local payload even when the probe fails without internet
|
|
392
|
+
return@retryWithDelay payload
|
|
375
393
|
}
|
|
376
394
|
null
|
|
377
395
|
}
|