@simba-dev/react-native-media-player 1.15.0 → 1.17.0
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/cpp/event.cpp +18 -1
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +256 -54
- package/package.json +1 -1
- package/src/bridge/MpvPlayerModule.ts +33 -4
- package/src/bridge/__tests__/errorContract.test.ts +17 -2
- package/src/components/DefaultControls.tsx +14 -13
- package/src/components/PlayerProvider.tsx +50 -38
- package/src/hooks/useLaunchPlayback.ts +17 -8
- package/src/hooks/useOpenWithResume.tsx +8 -8
- package/src/index.ts +23 -11
- package/src/types/__tests__/player.test.tsx +126 -1
- package/src/types/__tests__/playerLoading.test.ts +170 -0
- package/src/types/player.ts +159 -35
|
@@ -500,7 +500,24 @@ void eventLoop() {
|
|
|
500
500
|
// error. Fatal decoder/IO failures are not retryable
|
|
501
501
|
// without a different source, so we mark them
|
|
502
502
|
// non-recoverable.
|
|
503
|
-
|
|
503
|
+
// A fatal mpv LOG LINE is not proof that playback stopped.
|
|
504
|
+
//
|
|
505
|
+
// mpv's authoritative signal for "the file failed" is
|
|
506
|
+
// MPV_EVENT_END_FILE with a non-zero error code, and that
|
|
507
|
+
// path is handled above. A log line can be a SUBSYSTEM
|
|
508
|
+
// complaint while the picture keeps playing: on the
|
|
509
|
+
// emulator (no audio device) mpv logged "AudioTrack Init
|
|
510
|
+
// failed" at fatal level while the video played on, and
|
|
511
|
+
// the app covered the working video with a terminal error
|
|
512
|
+
// card. That is the same class of bug this file already
|
|
513
|
+
// guards against for `error`-level lines.
|
|
514
|
+
//
|
|
515
|
+
// So it is reported with an HONEST code and marked
|
|
516
|
+
// non-terminal: `recoverable=true` means "playback
|
|
517
|
+
// continued", which is the fact. The previous `-1` was a
|
|
518
|
+
// fabricated sentinel that collided with
|
|
519
|
+
// MPV_ERROR_EVENT_QUEUE_FULL and read as a real code.
|
|
520
|
+
callJavaError(MPV_ERROR_GENERIC, log->text ? log->text : "mpv fatal error", requestId.c_str(), /*recoverable=*/true);
|
|
504
521
|
}
|
|
505
522
|
break;
|
|
506
523
|
}
|
|
@@ -233,6 +233,21 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
233
233
|
* Property observers requested by JS before native initialization completes.
|
|
234
234
|
* Keep them until the handle exists instead of silently dropping them.
|
|
235
235
|
*/
|
|
236
|
+
/**
|
|
237
|
+
* Property names this module has already logged, so each one is
|
|
238
|
+
* announced exactly once per session.
|
|
239
|
+
*
|
|
240
|
+
* The per-value property log was made a compile-time constant in
|
|
241
|
+
* v1.10.0 (it fired 30-60x/second for `time-pos`). That made the
|
|
242
|
+
* whole property path UNOBSERVABLE: no build could answer "does this
|
|
243
|
+
* property ever arrive?", which is why a delivery defect could sit
|
|
244
|
+
* here for a release cycle with nothing to contradict it.
|
|
245
|
+
*
|
|
246
|
+
* One line per property per session answers that question at no
|
|
247
|
+
* ongoing cost, so this stays unconditional.
|
|
248
|
+
*/
|
|
249
|
+
private val announcedProperties = java.util.concurrent.ConcurrentHashMap.newKeySet<String>()
|
|
250
|
+
|
|
236
251
|
private val pendingObservedProperties = linkedSetOf<String>()
|
|
237
252
|
|
|
238
253
|
/**
|
|
@@ -292,6 +307,12 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
292
307
|
// to discard them) and performing a synchronous write to logd.
|
|
293
308
|
// Gate it behind the same debug switch as the JS dlog(); the
|
|
294
309
|
// property value is still delivered to JS regardless.
|
|
310
|
+
// First arrival of each property, once per session. This is the
|
|
311
|
+
// observable that was missing: with it, a device log answers
|
|
312
|
+
// "does this property ever arrive?" without a rebuild.
|
|
313
|
+
if (announcedProperties.add(name)) {
|
|
314
|
+
Log.i(TAG, "[PlaybackTrace][Bridge][property:first] name=$name")
|
|
315
|
+
}
|
|
295
316
|
if (TRACE_PROPERTY_EVENTS) {
|
|
296
317
|
Log.d(TAG, "[PlaybackTrace][Bridge][listener:property] name=$name value=$jsonValue")
|
|
297
318
|
}
|
|
@@ -331,25 +352,44 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
331
352
|
// `percent > 0 && percent < 100` correctly drops the spinner.
|
|
332
353
|
when (name) {
|
|
333
354
|
"cache-buffering-state" -> {
|
|
355
|
+
// The cache FILL LEVEL. It is NOT a stall signal.
|
|
356
|
+
//
|
|
357
|
+
// mpv reports `cache-buffering-state` as the percentage
|
|
358
|
+
// of the cache that is filled, and a partially-filled
|
|
359
|
+
// cache is the NORMAL state during playback. The old
|
|
360
|
+
// code read it as "isBuffering = percent < 100", which
|
|
361
|
+
// is true for most of a stream's life — so the flag
|
|
362
|
+
// flickered with every refill and the spinner could
|
|
363
|
+
// latch on during perfectly healthy playback.
|
|
364
|
+
//
|
|
365
|
+
// The stall signal is `paused-for-cache`, which is a
|
|
366
|
+
// different property with a different owner. One fact,
|
|
367
|
+
// one owner: this one owns the fill, that one owns the
|
|
368
|
+
// stall.
|
|
334
369
|
val percent = parseBufferingPercent(jsonValue)
|
|
335
370
|
try {
|
|
336
|
-
val
|
|
371
|
+
val fillPayload = Arguments.createMap().apply {
|
|
337
372
|
putDouble("percent", percent)
|
|
338
|
-
putBoolean("isBuffering", percent < 100.0)
|
|
339
373
|
}
|
|
340
|
-
eventEmitter.emit("
|
|
374
|
+
eventEmitter.emit("onCacheFill", fillPayload)
|
|
341
375
|
} catch (e: Exception) {
|
|
342
|
-
Log.w(TAG, "
|
|
376
|
+
Log.w(TAG, "onCacheFill emit failed: ${e.message}")
|
|
343
377
|
}
|
|
344
378
|
}
|
|
345
|
-
// `paused-for-cache` is the universal stall signal
|
|
346
|
-
//
|
|
347
|
-
//
|
|
379
|
+
// `paused-for-cache` is the universal stall signal: mpv sets
|
|
380
|
+
// it exactly while playback is paused because the cache
|
|
381
|
+
// underran. It is a BOOLEAN, and it is the only thing that
|
|
382
|
+
// may drive `isBuffering`.
|
|
383
|
+
//
|
|
384
|
+
// It carries no percentage. It does not know the fill, and
|
|
385
|
+
// the old code invented one (0 when stalled, 100 when not)
|
|
386
|
+
// which then overwrote the real fill with a fabricated
|
|
387
|
+
// number — the same "one fact, two owners" failure as
|
|
388
|
+
// above, in the other direction.
|
|
348
389
|
"paused-for-cache" -> {
|
|
349
390
|
val isBuffering = jsonValue.trim().equals("true", ignoreCase = true)
|
|
350
391
|
try {
|
|
351
392
|
val bufPayload = Arguments.createMap().apply {
|
|
352
|
-
putDouble("percent", if (isBuffering) 0.0 else 100.0)
|
|
353
393
|
putBoolean("isBuffering", isBuffering)
|
|
354
394
|
}
|
|
355
395
|
eventEmitter.emit("onBuffering", bufPayload)
|
|
@@ -358,10 +398,34 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
358
398
|
}
|
|
359
399
|
}
|
|
360
400
|
// `demuxer-cache-state` carries the buffered ranges — the
|
|
361
|
-
// grey overlay on the seek bar.
|
|
362
|
-
//
|
|
363
|
-
//
|
|
364
|
-
//
|
|
401
|
+
// grey overlay on the seek bar.
|
|
402
|
+
//
|
|
403
|
+
// MEASURED against mpv's own source (2026-10-19). Each entry
|
|
404
|
+
// of `seekable-ranges` is `{start, end}` and NOTHING else:
|
|
405
|
+
// mpv's `mp_property_demuxer_cache_state` adds exactly those
|
|
406
|
+
// two doubles per range (mpv's `player/command.c`). There
|
|
407
|
+
// are no `flags`.
|
|
408
|
+
//
|
|
409
|
+
// And they are NOT the file's seekable extent. mpv derives
|
|
410
|
+
// them in `update_seek_ranges()` (mpv's `demux/demux.c`)
|
|
411
|
+
// from the demux queue's PACKET extent, so they are the time
|
|
412
|
+
// spans of the data mpv currently HOLDS — the buffer islands
|
|
413
|
+
// a seek bar has to draw. (A range's `is_bof`, which mpv
|
|
414
|
+
// does not put in the node, is what says whether that span
|
|
415
|
+
// still starts at the beginning of the file.)
|
|
416
|
+
//
|
|
417
|
+
// So a consumer that paints these as "buffered" is painting
|
|
418
|
+
// the truth, and one that reads them as "how long the file
|
|
419
|
+
// is" is not.
|
|
420
|
+
//
|
|
421
|
+
// The ranges leave this bridge in MILLISECONDS. mpv reports
|
|
422
|
+
// `seekable-ranges` in seconds, and the bridge is the only
|
|
423
|
+
// place that knows which unit a payload carried — so the
|
|
424
|
+
// bridge is the only place that converts it. Every other
|
|
425
|
+
// time value on this API (positionMs, durationMs) is
|
|
426
|
+
// milliseconds, and a consumer that had to guess the unit
|
|
427
|
+
// of one field among them is a consumer that will get it
|
|
428
|
+
// wrong.
|
|
365
429
|
"demuxer-cache-state" -> {
|
|
366
430
|
try {
|
|
367
431
|
val parsed = parseCacheState(jsonValue)
|
|
@@ -375,7 +439,6 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
375
439
|
}
|
|
376
440
|
val cachePayload = Arguments.createMap().apply {
|
|
377
441
|
putArray("ranges", rangesArray)
|
|
378
|
-
putDouble("fill", parsed.fill)
|
|
379
442
|
}
|
|
380
443
|
eventEmitter.emit("onCacheState", cachePayload)
|
|
381
444
|
} catch (e: Exception) {
|
|
@@ -425,29 +488,40 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
425
488
|
|
|
426
489
|
override fun onMpvError(code: Int, recoverable: Boolean, message: String, requestId: String?) {
|
|
427
490
|
Log.e(TAG, "[PlaybackTrace][Bridge][listener:error] code=$code recoverable=$recoverable requestId=${requestId ?: "none"} message=$message")
|
|
428
|
-
//
|
|
429
|
-
//
|
|
430
|
-
//
|
|
431
|
-
//
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
//
|
|
445
|
-
//
|
|
446
|
-
//
|
|
447
|
-
//
|
|
448
|
-
|
|
491
|
+
// Map the libmpv error code to the lib's stable string
|
|
492
|
+
// contract.
|
|
493
|
+
//
|
|
494
|
+
// It used to be `!recoverable -> "E_RENDERER_GONE"` FIRST,
|
|
495
|
+
// so EVERY terminal failure claimed the renderer process had
|
|
496
|
+
// died — including a plain load failure (-13) and a generic
|
|
497
|
+
// failure (-20). The app's classifier had nothing to switch
|
|
498
|
+
// on, and every failure rendered the same "Something went
|
|
499
|
+
// wrong" card.
|
|
500
|
+
//
|
|
501
|
+
// mpv's numeric code is the primary signal (mpv
|
|
502
|
+
// `include/mpv/client.h`, `mpv_error`). The message
|
|
503
|
+
// heuristics stay as the FALLBACK for the codes that carry
|
|
504
|
+
// no information of their own.
|
|
505
|
+
val mappedCode = mapMpvErrorCode(code, message)
|
|
506
|
+
// Emit ONCE.
|
|
507
|
+
//
|
|
508
|
+
// This used to emit `onError` TWICE: once through
|
|
509
|
+
// `emitErrorEvent` (numeric `code` + `codeName`) and
|
|
510
|
+
// then again with `putString("code", mappedCode)` — a
|
|
511
|
+
// STRING, where the TS contract declares `code: number`.
|
|
512
|
+
// The second emission overwrote the first, so the app read
|
|
513
|
+
// `Number("E_RENDERER_GONE")` => NaN, and the device log
|
|
514
|
+
// showed `numeric=0` for a real failure.
|
|
515
|
+
//
|
|
516
|
+
// `recoverable` means "playback continued". mpv's END_FILE
|
|
517
|
+
// path (the file failed) reports it as false; a fatal-level
|
|
518
|
+
// mpv LOG line reports true, because a log line is not proof
|
|
519
|
+
// that playback ended.
|
|
520
|
+
val numeric = codeToNumeric(mappedCode)
|
|
521
|
+
Log.w(TAG, "[PlaybackTrace][Bridge][error] code=$mappedCode numeric=$numeric nativeCode=$code recoverable=$recoverable message=$message")
|
|
449
522
|
val payload = Arguments.createMap().apply {
|
|
450
|
-
|
|
523
|
+
putInt("code", numeric)
|
|
524
|
+
putString("codeName", mappedCode)
|
|
451
525
|
putInt("nativeCode", code)
|
|
452
526
|
putBoolean("recoverable", recoverable)
|
|
453
527
|
putString("message", message)
|
|
@@ -457,6 +531,39 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
457
531
|
}
|
|
458
532
|
}
|
|
459
533
|
|
|
534
|
+
/**
|
|
535
|
+
* Announce that a load has been REQUESTED.
|
|
536
|
+
*
|
|
537
|
+
* This is the "the file is opening" signal, and it has to come from
|
|
538
|
+
* here because no consumer can derive it: mpv's core state is
|
|
539
|
+
* "playing" from the moment `loadfile` is called until the file has
|
|
540
|
+
* been parsed, so a consumer deriving a phase from `isPlaying` can
|
|
541
|
+
* never tell "opening" from "playing".
|
|
542
|
+
*
|
|
543
|
+
* Device evidence (2026-10-20): a 9-second load over a throttled
|
|
544
|
+
* link showed NO loading indicator at all — the file was still
|
|
545
|
+
* opening, and the only two phases available were "playing" (the
|
|
546
|
+
* engine had been told to play) and "idle" (the playlist had not
|
|
547
|
+
* been populated yet). Neither of them is the truth.
|
|
548
|
+
*
|
|
549
|
+
* `onFileLoaded` (mpv's EVENT_FILE_LOADED) is the other end of the
|
|
550
|
+
* window. Between the two, the file is opening, and that is exactly
|
|
551
|
+
* when a loading indicator belongs on screen.
|
|
552
|
+
*
|
|
553
|
+
* Emitted BEFORE the native call, so the consumer sees "opening" for
|
|
554
|
+
* the whole of the load rather than after it.
|
|
555
|
+
*/
|
|
556
|
+
private fun emitLoadRequested(uri: String) {
|
|
557
|
+
try {
|
|
558
|
+
val payload = Arguments.createMap().apply {
|
|
559
|
+
putString("uri", uri)
|
|
560
|
+
}
|
|
561
|
+
eventEmitter.emit("onLoadRequested", payload)
|
|
562
|
+
} catch (e: Exception) {
|
|
563
|
+
Log.w(TAG, "onLoadRequested emit failed: ${e.message}")
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
460
567
|
private fun emitNumericEvent(eventName: String, key: String, rawValue: String) {
|
|
461
568
|
val value = rawValue.trim().trim('"').toDoubleOrNull() ?: return
|
|
462
569
|
try {
|
|
@@ -1000,6 +1107,7 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
1000
1107
|
ensurePtr()
|
|
1001
1108
|
val resolvedPath = normalizeMpvInput(resolveContentUri(path))
|
|
1002
1109
|
Log.i(TAG, "[PlaybackTrace][Bridge][loadFile] requested=$path resolved=$resolvedPath ptr=$nativePtr")
|
|
1110
|
+
emitLoadRequested(path)
|
|
1003
1111
|
try {
|
|
1004
1112
|
MPVLib.nativeLoadFile(nativePtr, resolvedPath)
|
|
1005
1113
|
Log.i(TAG, "[PlaybackTrace][Bridge][loadFile] nativeLoadFile returned")
|
|
@@ -1019,6 +1127,7 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
1019
1127
|
}
|
|
1020
1128
|
val resolvedPath = normalizeMpvInput(resolveContentUri(path))
|
|
1021
1129
|
Log.i(TAG, "[PlaybackTrace][Bridge][loadFileWithRequestId] requested=$path resolved=$resolvedPath requestId=$requestId ptr=$nativePtr")
|
|
1130
|
+
emitLoadRequested(path)
|
|
1022
1131
|
try {
|
|
1023
1132
|
MPVLib.nativeLoadFileWithRequestId(nativePtr, resolvedPath, requestId)
|
|
1024
1133
|
Log.i(TAG, "[PlaybackTrace][Bridge][loadFileWithRequestId] nativeLoadFileWithRequestId returned requestId=$requestId")
|
|
@@ -2439,53 +2548,126 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2439
2548
|
}
|
|
2440
2549
|
|
|
2441
2550
|
/**
|
|
2442
|
-
* Parse a `demuxer-cache-state` payload into buffered ranges
|
|
2551
|
+
* Parse a `demuxer-cache-state` payload into buffered ranges.
|
|
2443
2552
|
*
|
|
2444
|
-
|
|
2553
|
+
* MPV serialises this property as a node map whose documented fields
|
|
2445
2554
|
* include `seekable-ranges`, `bof-cached`, `eof-cached`, `fw-bytes`,
|
|
2446
2555
|
* `file-cache-bytes`, `cache-end`, `reader-pts`, and `cache-duration`.
|
|
2447
2556
|
* The seekable ranges are the authoritative buffered timeline ranges.
|
|
2448
2557
|
*
|
|
2449
|
-
*
|
|
2450
|
-
*
|
|
2451
|
-
*
|
|
2452
|
-
*
|
|
2453
|
-
|
|
2558
|
+
* ## The unit
|
|
2559
|
+
*
|
|
2560
|
+
* `seekable-ranges` is in SECONDS, relative to the stream start. The
|
|
2561
|
+
* ranges leave this bridge in MILLISECONDS, because the bridge is the
|
|
2562
|
+
* only layer that knows which unit a payload carried.
|
|
2563
|
+
*
|
|
2564
|
+
* The legacy `ranges` field is BYTE OFFSETS, and a byte offset is not
|
|
2565
|
+
* a time: there is no constant bytes-per-second to divide by, because
|
|
2566
|
+
* the bitrate varies and a VBR stream has no single one. The old code
|
|
2567
|
+
* read `ranges` as if it were `seekable-ranges` and forwarded it
|
|
2568
|
+
* unlabelled, and the consumer read the numbers as milliseconds. So a
|
|
2569
|
+
* 60-second range arrived as 60 ms, and a byte range was clamped to
|
|
2570
|
+
* the duration and painted as a full-width "100% buffered" bar — a bar
|
|
2571
|
+
* claiming that data is buffered when it is not.
|
|
2572
|
+
*
|
|
2573
|
+
* So the byte field is read, logged, and NOT forwarded as a time
|
|
2574
|
+
* range. A seek bar that shows nothing is honest; a seek bar that
|
|
2575
|
+
* shows a false 100% is not.
|
|
2576
|
+
*
|
|
2577
|
+
* Cache fill is intentionally not derived from byte counts: mpv
|
|
2578
|
+
* exposes the user-facing fill percentage through the separate
|
|
2579
|
+
* `cache-buffering-state` property, which is mapped to `onCacheFill`.
|
|
2454
2580
|
*/
|
|
2455
2581
|
private data class CacheStatePayload(
|
|
2582
|
+
/** Buffered ranges in MILLISECONDS, relative to the stream start. */
|
|
2456
2583
|
val ranges: List<Pair<Double, Double>>,
|
|
2457
|
-
val fill: Double,
|
|
2458
2584
|
)
|
|
2459
2585
|
|
|
2460
2586
|
private fun parseCacheState(jsonValue: String): CacheStatePayload {
|
|
2461
2587
|
val trimmed = jsonValue.trim()
|
|
2462
2588
|
if (trimmed.isEmpty() || trimmed == "null") {
|
|
2463
|
-
return CacheStatePayload(emptyList()
|
|
2589
|
+
return CacheStatePayload(emptyList())
|
|
2464
2590
|
}
|
|
2465
2591
|
return try {
|
|
2466
2592
|
val obj = JSONObject(trimmed)
|
|
2467
|
-
val
|
|
2468
|
-
|
|
2593
|
+
val seekableJson = obj.optJSONArray("seekable-ranges")
|
|
2594
|
+
val legacyByteJson = obj.optJSONArray("ranges")
|
|
2469
2595
|
|
|
2470
2596
|
val ranges = mutableListOf<Pair<Double, Double>>()
|
|
2471
|
-
if (
|
|
2472
|
-
for (i in 0 until
|
|
2473
|
-
val r =
|
|
2597
|
+
if (seekableJson != null) {
|
|
2598
|
+
for (i in 0 until seekableJson.length()) {
|
|
2599
|
+
val r = seekableJson.optJSONObject(i) ?: continue
|
|
2474
2600
|
val start = r.optDouble("start", Double.NaN)
|
|
2475
2601
|
val end = r.optDouble("end", Double.NaN)
|
|
2476
2602
|
if (!start.isNaN() && !end.isNaN() && end > start) {
|
|
2477
|
-
|
|
2603
|
+
// seconds -> milliseconds
|
|
2604
|
+
ranges.add(start * 1000.0 to end * 1000.0)
|
|
2478
2605
|
}
|
|
2479
2606
|
}
|
|
2607
|
+
} else if (legacyByteJson != null) {
|
|
2608
|
+
Log.w(
|
|
2609
|
+
TAG,
|
|
2610
|
+
"parseCacheState: payload carries byte-offset 'ranges' and no " +
|
|
2611
|
+
"'seekable-ranges'. Byte offsets are not time positions, so no " +
|
|
2612
|
+
"buffered range is forwarded — painting them on a seek bar " +
|
|
2613
|
+
"would claim unbuffered data is buffered.",
|
|
2614
|
+
)
|
|
2480
2615
|
}
|
|
2481
|
-
|
|
2616
|
+
CacheStatePayload(ranges)
|
|
2482
2617
|
|
|
2483
2618
|
} catch (e: Exception) {
|
|
2484
2619
|
Log.w(TAG, "parseCacheState: bad json '$jsonValue': ${e.message}")
|
|
2485
|
-
CacheStatePayload(emptyList()
|
|
2620
|
+
CacheStatePayload(emptyList())
|
|
2486
2621
|
}
|
|
2487
2622
|
}
|
|
2488
2623
|
|
|
2624
|
+
/**
|
|
2625
|
+
* Map an mpv error code to the lib's stable string contract.
|
|
2626
|
+
*
|
|
2627
|
+
* mpv's numeric codes are authoritative (`include/mpv/client.h`,
|
|
2628
|
+
* `mpv_error`): -13 LOADING_FAILED, -14 AO_INIT_FAILED, -15
|
|
2629
|
+
* VO_INIT_FAILED, -16 NOTHING_TO_PLAY, -17 UNKNOWN_FORMAT, -18
|
|
2630
|
+
* UNSUPPORTED, -20 GENERIC, plus the API-level codes -1..-12.
|
|
2631
|
+
*
|
|
2632
|
+
* The message heuristics are the FALLBACK, for the codes that carry
|
|
2633
|
+
* no information of their own.
|
|
2634
|
+
*
|
|
2635
|
+
* `E_RENDERER_GONE` is deliberately NOT the catch-all any more: it
|
|
2636
|
+
* means "the video output died", and a load failure is not that.
|
|
2637
|
+
*/
|
|
2638
|
+
private fun mapMpvErrorCode(code: Int, message: String): String = when (code) {
|
|
2639
|
+
-13 -> "E_LOAD_FAILED"
|
|
2640
|
+
-14 -> "E_AUDIO_INIT_FAILED"
|
|
2641
|
+
-15 -> "E_VIDEO_INIT_FAILED"
|
|
2642
|
+
-16 -> "E_NOTHING_TO_PLAY"
|
|
2643
|
+
-17 -> "E_UNKNOWN_FORMAT"
|
|
2644
|
+
-18 -> "E_UNSUPPORTED_CODEC"
|
|
2645
|
+
-19 -> "E_NOT_IMPLEMENTED"
|
|
2646
|
+
-2 -> "E_OUT_OF_MEMORY"
|
|
2647
|
+
-3 -> "E_NOT_INITIALIZED"
|
|
2648
|
+
-4 -> "E_INVALID_PARAMETER"
|
|
2649
|
+
-5 -> "E_OPTION_NOT_FOUND"
|
|
2650
|
+
-8 -> "E_PROPERTY_NOT_FOUND"
|
|
2651
|
+
-12 -> "E_COMMAND_FAILED"
|
|
2652
|
+
else -> messageFallbackCode(message)
|
|
2653
|
+
}
|
|
2654
|
+
|
|
2655
|
+
/**
|
|
2656
|
+
* The message-based fallback, for an mpv code that says nothing about
|
|
2657
|
+
* what went wrong.
|
|
2658
|
+
*/
|
|
2659
|
+
private fun messageFallbackCode(message: String): String = when {
|
|
2660
|
+
message.contains("network", ignoreCase = true) ||
|
|
2661
|
+
message.contains("Connection refused", ignoreCase = true) ||
|
|
2662
|
+
message.contains("Connection timed out", ignoreCase = true) -> "E_NETWORK_FAILURE"
|
|
2663
|
+
message.contains("codec", ignoreCase = true) ||
|
|
2664
|
+
message.contains("format", ignoreCase = true) ||
|
|
2665
|
+
message.contains("unsupported", ignoreCase = true) -> "E_UNSUPPORTED_CODEC"
|
|
2666
|
+
message.contains("No such file", ignoreCase = true) ||
|
|
2667
|
+
message.contains("not found", ignoreCase = true) -> "E_FILE_NOT_FOUND"
|
|
2668
|
+
else -> "E_GENERIC"
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2489
2671
|
/**
|
|
2490
2672
|
* T28.03: stable integer mapping for the structured error codes emitted
|
|
2491
2673
|
* by [emitErrorEvent]. The TS `onError` interface declares `code: number`
|
|
@@ -2496,8 +2678,9 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2496
2678
|
* 1xxx - Initialization lifecycle (mount order, warm-up, ensurePtr)
|
|
2497
2679
|
* 2xxx - Activity / Intent / launch failures (PlayerActivity missing,
|
|
2498
2680
|
* SecurityException, manifest mismatches)
|
|
2499
|
-
* 3xxx - Playback
|
|
2500
|
-
*
|
|
2681
|
+
* 3xxx - Playback failures (load failed, audio/video output init
|
|
2682
|
+
* failed, unknown format, unsupported, network, file not
|
|
2683
|
+
* found) - in use since v1.17.0
|
|
2501
2684
|
* 4xxx - Configuration / IPC errors (setConfig parse failures,
|
|
2502
2685
|
* bridge serialisation mismatches)
|
|
2503
2686
|
*
|
|
@@ -2511,6 +2694,25 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
2511
2694
|
"E_ACTIVITY_NOT_FOUND" -> 2001
|
|
2512
2695
|
"E_SECURITY" -> 2002
|
|
2513
2696
|
"E_OPEN_PLAYER_FAILED" -> 2003
|
|
2697
|
+
// 3xxx - Playback failures. These ship in v1.17.0; the numbers
|
|
2698
|
+
// are PERMANENT (do not reuse one for a different meaning).
|
|
2699
|
+
"E_LOAD_FAILED" -> 3001
|
|
2700
|
+
"E_AUDIO_INIT_FAILED" -> 3002
|
|
2701
|
+
"E_VIDEO_INIT_FAILED" -> 3003
|
|
2702
|
+
"E_NOTHING_TO_PLAY" -> 3004
|
|
2703
|
+
"E_UNKNOWN_FORMAT" -> 3005
|
|
2704
|
+
"E_UNSUPPORTED_CODEC" -> 3006
|
|
2705
|
+
"E_NETWORK_FAILURE" -> 3007
|
|
2706
|
+
"E_FILE_NOT_FOUND" -> 3008
|
|
2707
|
+
"E_DECODE_FAILED" -> 3009
|
|
2708
|
+
"E_RENDERER_GONE" -> 3010
|
|
2709
|
+
"E_GENERIC" -> 3011
|
|
2710
|
+
"E_OUT_OF_MEMORY" -> 3012
|
|
2711
|
+
"E_INVALID_PARAMETER" -> 3013
|
|
2712
|
+
"E_OPTION_NOT_FOUND" -> 3014
|
|
2713
|
+
"E_PROPERTY_NOT_FOUND" -> 3015
|
|
2714
|
+
"E_COMMAND_FAILED" -> 3016
|
|
2715
|
+
"E_NOT_IMPLEMENTED" -> 3017
|
|
2514
2716
|
// 4xxx - Configuration
|
|
2515
2717
|
"E_CONFIG_PARSE_FAILED" -> 4001
|
|
2516
2718
|
else -> 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simba-dev/react-native-media-player",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "React Native video & audio player powered by libmpv — Picture-in-Picture, MediaSession, foreground service, and a customizable TypeScript UI. Built for Android. Designed as a drop-in replacement for react-native-video / react-native-track-player / expo-av. See CHANGELOG.md for per-version notes.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -110,9 +110,10 @@ export interface LaunchParams {
|
|
|
110
110
|
readonly requestId?: string;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
/** All
|
|
113
|
+
/** All 23 events emitted by the Kotlin bridge. */
|
|
114
114
|
export type PlayerEventName =
|
|
115
115
|
| 'onFileLoaded'
|
|
116
|
+
| 'onLoadRequested'
|
|
116
117
|
| 'onPlaybackStateChanged'
|
|
117
118
|
| 'onPositionChanged'
|
|
118
119
|
| 'onDurationChanged'
|
|
@@ -122,6 +123,7 @@ export type PlayerEventName =
|
|
|
122
123
|
| 'onVideoParamsChanged'
|
|
123
124
|
| 'onError'
|
|
124
125
|
| 'onBuffering'
|
|
126
|
+
| 'onCacheFill'
|
|
125
127
|
| 'onCacheState'
|
|
126
128
|
| 'onSeekable'
|
|
127
129
|
| 'onSeeking'
|
|
@@ -140,6 +142,16 @@ export type PlayerEventName =
|
|
|
140
142
|
/** Typed payload map for each event. */
|
|
141
143
|
export interface PlayerEventPayloads {
|
|
142
144
|
onFileLoaded: { requestId?: string; resolvedPath?: string; file?: MpvFileInfo };
|
|
145
|
+
/**
|
|
146
|
+
* A load has been REQUESTED and the engine has not reported the file
|
|
147
|
+
* yet. v1.17.0.
|
|
148
|
+
*
|
|
149
|
+
* This is the "the file is opening" signal, and it cannot be derived
|
|
150
|
+
* by a consumer: mpv's core state is "playing" from the moment
|
|
151
|
+
* `loadfile` is called until the file has been parsed, so a phase
|
|
152
|
+
* derived from `isPlaying` can never tell "opening" from "playing".
|
|
153
|
+
*/
|
|
154
|
+
onLoadRequested: { uri?: string; requestId?: string };
|
|
143
155
|
onPlaybackStateChanged: { state: MpvPlaybackState };
|
|
144
156
|
onPositionChanged: { position: number };
|
|
145
157
|
onDurationChanged: { duration: number };
|
|
@@ -154,8 +166,23 @@ export interface PlayerEventPayloads {
|
|
|
154
166
|
message: string;
|
|
155
167
|
requestId?: string;
|
|
156
168
|
};
|
|
157
|
-
|
|
158
|
-
|
|
169
|
+
/**
|
|
170
|
+
* The STALL signal. True exactly while playback is paused because the
|
|
171
|
+
* cache underran. It carries no percentage: the property does not know
|
|
172
|
+
* the fill, and an invented one destroys the real fill.
|
|
173
|
+
*/
|
|
174
|
+
onBuffering: { isBuffering: boolean };
|
|
175
|
+
/**
|
|
176
|
+
* The cache FILL LEVEL, 0..100. A level, not a stall — a partially
|
|
177
|
+
* filled cache is the normal state during playback.
|
|
178
|
+
*/
|
|
179
|
+
onCacheFill: { percent: number };
|
|
180
|
+
/**
|
|
181
|
+
* The buffered timeline ranges, in MILLISECONDS, relative to the stream
|
|
182
|
+
* start. Byte offsets are never reported here: a byte offset is not a
|
|
183
|
+
* time.
|
|
184
|
+
*/
|
|
185
|
+
onCacheState: { ranges: Array<{ start: number; end: number }> };
|
|
159
186
|
onSeekable: { seekable: boolean };
|
|
160
187
|
onSeeking: { seeking: boolean };
|
|
161
188
|
onEndFile: { reason: number; error: number; requestId?: string };
|
|
@@ -956,9 +983,10 @@ export function removeAllListeners(event?: PlayerEventName): void {
|
|
|
956
983
|
}
|
|
957
984
|
}
|
|
958
985
|
|
|
959
|
-
/** All
|
|
986
|
+
/** All 23 player event names — used by `removeAllListeners()` to iterate when no event is specified. */
|
|
960
987
|
const ALL_PLAYER_EVENTS: readonly PlayerEventName[] = [
|
|
961
988
|
'onFileLoaded',
|
|
989
|
+
'onLoadRequested',
|
|
962
990
|
'onPlaybackStateChanged',
|
|
963
991
|
'onPositionChanged',
|
|
964
992
|
'onDurationChanged',
|
|
@@ -968,6 +996,7 @@ const ALL_PLAYER_EVENTS: readonly PlayerEventName[] = [
|
|
|
968
996
|
'onVideoParamsChanged',
|
|
969
997
|
'onError',
|
|
970
998
|
'onBuffering',
|
|
999
|
+
'onCacheFill',
|
|
971
1000
|
'onCacheState',
|
|
972
1001
|
'onSeekable',
|
|
973
1002
|
'onSeeking',
|
|
@@ -137,13 +137,28 @@ describe('Phase 38 — error code constants (consumer contract)', () => {
|
|
|
137
137
|
'E_OUT_OF_MEMORY',
|
|
138
138
|
'E_AUDIO_FOCUS_LOST',
|
|
139
139
|
'E_SURFACE_LOST',
|
|
140
|
+
// v1.17.0 — the mpv error codes, mapped from `mpv_error` in mpv's
|
|
141
|
+
// `include/mpv/client.h`. These replaced the "every terminal
|
|
142
|
+
// failure is E_RENDERER_GONE" catch-all, which made a load failure
|
|
143
|
+
// indistinguishable from a dead video output.
|
|
144
|
+
'E_LOAD_FAILED',
|
|
145
|
+
'E_AUDIO_INIT_FAILED',
|
|
146
|
+
'E_VIDEO_INIT_FAILED',
|
|
147
|
+
'E_NOTHING_TO_PLAY',
|
|
148
|
+
'E_UNKNOWN_FORMAT',
|
|
149
|
+
'E_GENERIC',
|
|
150
|
+
'E_NOT_IMPLEMENTED',
|
|
151
|
+
'E_INVALID_PARAMETER',
|
|
152
|
+
'E_OPTION_NOT_FOUND',
|
|
153
|
+
'E_PROPERTY_NOT_FOUND',
|
|
154
|
+
'E_COMMAND_FAILED',
|
|
140
155
|
];
|
|
141
156
|
|
|
142
|
-
it('exposes the
|
|
157
|
+
it('exposes the 26 documented error codes as a frozen contract', () => {
|
|
143
158
|
// The list itself is not exported from the module — it's
|
|
144
159
|
// documented in ERROR_CONTRACT.md. This test pins the list so
|
|
145
160
|
// a drift between docs and code fails CI.
|
|
146
|
-
expect(DOCUMENTED_ERROR_CODES).toHaveLength(
|
|
161
|
+
expect(DOCUMENTED_ERROR_CODES).toHaveLength(26);
|
|
147
162
|
});
|
|
148
163
|
|
|
149
164
|
it('error codes follow the E_UPPER_SNAKE_CASE convention', () => {
|
|
@@ -20,12 +20,12 @@ import { useTheme } from './PlayerProvider';
|
|
|
20
20
|
import { usePlayer, usePlayerProgress } from '../types/player';
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* The default controls component.
|
|
24
24
|
*
|
|
25
25
|
* Layout (top → bottom):
|
|
26
26
|
* 1. **Top bar**: close (✕) + title + spacer for future more-menu.
|
|
27
|
-
* 2. **Center**: empty
|
|
28
|
-
*
|
|
27
|
+
* 2. **Center**: empty — reserved for the loading spinner / error
|
|
28
|
+
* state / buffer indicator.
|
|
29
29
|
* 3. **Bottom bar**: time-current / scrubber / time-total + skip
|
|
30
30
|
* back / play-pause / skip forward.
|
|
31
31
|
*
|
|
@@ -41,9 +41,10 @@ import { usePlayer, usePlayerProgress } from '../types/player';
|
|
|
41
41
|
* is `theme.background` with reduced opacity, so it harmonises with
|
|
42
42
|
* the consumer's theme in dark / light / brand-color modes.
|
|
43
43
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* `usePlayerProgress()
|
|
44
|
+
* The commands are wired to the `MpvPlayerModule` bridge, so play /
|
|
45
|
+
* pause / seek actually drive mpv. Progress comes from
|
|
46
|
+
* `usePlayerProgress()`, which is fed by the native mpv event
|
|
47
|
+
* stream — there is no JS-side position poll.
|
|
47
48
|
*/
|
|
48
49
|
|
|
49
50
|
const AUTO_HIDE_TIMEOUT_MS = 3000;
|
|
@@ -70,9 +71,9 @@ export interface DefaultControlsProps {
|
|
|
70
71
|
onPause?: () => void;
|
|
71
72
|
/**
|
|
72
73
|
* V22.0.0 / 1.5.8 (D-035 fix #4): handler for the close ✕ button
|
|
73
|
-
* (top-left). PlayerRoot wires this to `bridge.exitPipAndFinish()
|
|
74
|
-
* which dismisses the
|
|
75
|
-
* back to `onPause` (matches the V21 behaviour that had no
|
|
74
|
+
* (top-left). PlayerRoot wires this to `bridge.exitPipAndFinish()`,
|
|
75
|
+
* which dismisses the player UI and leaves PiP. When omitted, the
|
|
76
|
+
* ✕ falls back to `onPause` (matches the V21 behaviour that had no
|
|
76
77
|
* dedicated close).
|
|
77
78
|
*/
|
|
78
79
|
onClose?: () => void;
|
|
@@ -300,13 +301,13 @@ export function DefaultControls(props: DefaultControlsProps = {}): React.ReactEl
|
|
|
300
301
|
</Text>
|
|
301
302
|
) : null}
|
|
302
303
|
</View>
|
|
303
|
-
{/* Spacer to keep the title centred;
|
|
304
|
-
|
|
304
|
+
{/* Spacer to keep the title centred; reserved for a
|
|
305
|
+
more-menu icon. */}
|
|
305
306
|
<View style={styles.iconButton} />
|
|
306
307
|
</View>
|
|
307
308
|
|
|
308
|
-
{/* Center:
|
|
309
|
-
|
|
309
|
+
{/* Center: reserved for the loading / error / buffer
|
|
310
|
+
indicator (the empty View keeps the top + bottom bars
|
|
310
311
|
pinned to the edges via flex layout.) */}
|
|
311
312
|
<View style={styles.center} />
|
|
312
313
|
|