@simba-dev/react-native-media-player 1.18.0 → 1.20.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/main.cpp +51 -3
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +112 -21
- package/package.json +1 -1
- package/src/bridge/MpvPlayerModule.ts +1 -1
- package/src/bridge/NativeMpvPlayer.ts +8 -1
- package/src/types/__tests__/player.pipArity.test.tsx +74 -0
- package/src/types/player.ts +22 -5
|
@@ -241,28 +241,76 @@ Java_com_simba_player_mpv_MPVLib_nativeCreate(JNIEnv *env, jclass, jstring caFil
|
|
|
241
241
|
//
|
|
242
242
|
// • cache=yes : enable a RAM cache even for non-network
|
|
243
243
|
// sources (so seek-back is instant).
|
|
244
|
-
// • cache-secs=
|
|
244
|
+
// • cache-secs=300 : keep ~5 minutes of stream ahead of the
|
|
245
245
|
// playhead in RAM. Big enough to absorb a
|
|
246
246
|
// brief re-buffer without a spinner, small
|
|
247
247
|
// enough to stay under mobile RAM limits.
|
|
248
|
+
//
|
|
249
|
+
// This was 120 s, and 120 s is not enough to
|
|
250
|
+
// SEE. The buffered range a consumer draws
|
|
251
|
+
// is the span between the playhead and the
|
|
252
|
+
// end of the buffer, and the seek bar's thumb
|
|
253
|
+
// covers 3.04 % of the track (a 14 dp thumb on
|
|
254
|
+
// a 230 dp rail). On a feature-length film
|
|
255
|
+
// 120 s is 2.44 % of the file — LESS than
|
|
256
|
+
// the thumb — so the thumb covered the whole
|
|
257
|
+
// visible band and the buffered indicator
|
|
258
|
+
// could not be seen at all. Measured on
|
|
259
|
+
// device (2026-10-20): track 690 px, band
|
|
260
|
+
// 16 px, thumb half-width 21 px. 300 s is
|
|
261
|
+
// 6.1 % of the same film, so the band
|
|
262
|
+
// clears the thumb.
|
|
248
263
|
// • demuxer-max-bytes : hard upper bound on the cache size in
|
|
249
264
|
// bytes (≈150 MB). Prevents OOM on large
|
|
250
265
|
// VOD files over HTTP.
|
|
266
|
+
//
|
|
267
|
+
// This is the SECOND bound on how far
|
|
268
|
+
// the buffered band can reach: 300 s of
|
|
269
|
+
// video only fits in 150 MB at ≤4 Mbit/s,
|
|
270
|
+
// so above that bitrate the byte cap
|
|
271
|
+
// binds first and the band is shorter
|
|
272
|
+
// than 300 s. The band was measured on
|
|
273
|
+
// device rather than assumed.
|
|
251
274
|
// • demuxer-max-back-bytes : how far backwards the cache retains
|
|
252
275
|
// data (~75 MB). This is what makes
|
|
253
276
|
// "seek back 30 s" instantaneous.
|
|
254
277
|
// • demuxer-readahead-secs : how many seconds of stream to prefetch
|
|
255
278
|
// ahead of the playhead.
|
|
279
|
+
//
|
|
280
|
+
// It is NOT independent of `cache-secs`.
|
|
281
|
+
// mpv computes the demuxer's read-ahead
|
|
282
|
+
// target as the MAXIMUM of the two —
|
|
283
|
+
// mpv `demux/demux.c`, `update_opts()`:
|
|
284
|
+
//
|
|
285
|
+
// in->min_secs = opts->min_secs; // readahead
|
|
286
|
+
// if (use_cache)
|
|
287
|
+
// in->min_secs = MPMAX(in->min_secs,
|
|
288
|
+
// opts->min_secs_cache);
|
|
289
|
+
// // cache-secs
|
|
290
|
+
//
|
|
291
|
+
// `update_opts()` re-runs on EVERY config
|
|
292
|
+
// change, so the two must be raised AND
|
|
293
|
+
// lowered together. That is why the runtime
|
|
294
|
+
// memory-pressure trim in
|
|
295
|
+
// `MpvBridgeModule.onTrimMemory` writes
|
|
296
|
+
// BOTH — trimming only `cache-secs` would
|
|
297
|
+
// leave the read-ahead pinned and the trim
|
|
298
|
+
// would have no effect at all.
|
|
299
|
+
//
|
|
300
|
+
// The span between the playhead and the end
|
|
301
|
+
// of the buffer is exactly what a consumer
|
|
302
|
+
// paints as its buffered range, so this
|
|
303
|
+
// value is what makes that span visible.
|
|
256
304
|
// • demuxer-termination-timeout : if a network read stalls, fail
|
|
257
305
|
// the demuxer so the player can recover
|
|
258
306
|
// instead of hanging forever.
|
|
259
307
|
// • prefetch-playlist=yes : proactively fetch the next playlist
|
|
260
308
|
// entry (HLS / DASH) to enable gapless.
|
|
261
309
|
mpv_set_option_string(mpv, "cache", "yes");
|
|
262
|
-
mpv_set_option_string(mpv, "cache-secs", "
|
|
310
|
+
mpv_set_option_string(mpv, "cache-secs", "300");
|
|
263
311
|
mpv_set_option_string(mpv, "demuxer-max-bytes", "150MiB");
|
|
264
312
|
mpv_set_option_string(mpv, "demuxer-max-back-bytes", "75MiB");
|
|
265
|
-
mpv_set_option_string(mpv, "demuxer-readahead-secs", "
|
|
313
|
+
mpv_set_option_string(mpv, "demuxer-readahead-secs", "300");
|
|
266
314
|
mpv_set_option_string(mpv, "demuxer-termination-timeout", "10");
|
|
267
315
|
mpv_set_option_string(mpv, "prefetch-playlist", "yes");
|
|
268
316
|
|
|
@@ -31,7 +31,8 @@ import org.json.JSONObject
|
|
|
31
31
|
*/
|
|
32
32
|
@ReactModule(name = MpvBridgeModule.NAME)
|
|
33
33
|
class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
34
|
-
NativeMpvPlayerSpec(reactContext)
|
|
34
|
+
NativeMpvPlayerSpec(reactContext),
|
|
35
|
+
android.content.ComponentCallbacks2 {
|
|
35
36
|
|
|
36
37
|
companion object {
|
|
37
38
|
const val NAME = "MpvPlayerModule"
|
|
@@ -1105,6 +1106,12 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
1105
1106
|
@Override
|
|
1106
1107
|
override fun loadFile(path: String) {
|
|
1107
1108
|
ensurePtr()
|
|
1109
|
+
// A new file gets the FULL prefetch window. A previous
|
|
1110
|
+
// memory-pressure trim reduced it, and without this the
|
|
1111
|
+
// reduction would persist for the rest of the process, leaving
|
|
1112
|
+
// every later playback with a 10 s buffer — and therefore an
|
|
1113
|
+
// invisible buffered band.
|
|
1114
|
+
applyCacheWindow(baseCacheWindowSecs, "new load")
|
|
1108
1115
|
val resolvedPath = normalizeMpvInput(resolveContentUri(path))
|
|
1109
1116
|
Log.i(TAG, "[PlaybackTrace][Bridge][loadFile] requested=$path resolved=$resolvedPath ptr=$nativePtr")
|
|
1110
1117
|
emitLoadRequested(path)
|
|
@@ -1121,6 +1128,9 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
1121
1128
|
@Override
|
|
1122
1129
|
override fun loadFileWithRequestId(path: String, requestId: String) {
|
|
1123
1130
|
ensurePtr()
|
|
1131
|
+
// Same reasoning as `loadFile`: a new file restores the full
|
|
1132
|
+
// prefetch window after any memory-pressure trim.
|
|
1133
|
+
applyCacheWindow(baseCacheWindowSecs, "new load")
|
|
1124
1134
|
if (requestId.isBlank()) {
|
|
1125
1135
|
loadFile(path)
|
|
1126
1136
|
return
|
|
@@ -1748,23 +1758,87 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
1748
1758
|
}
|
|
1749
1759
|
|
|
1750
1760
|
/**
|
|
1751
|
-
*
|
|
1752
|
-
*
|
|
1753
|
-
* PlayerActivity.onCreate; called by the system when the process
|
|
1754
|
-
* is at a trim level.
|
|
1761
|
+
* The prefetch / cache window, in seconds, used when the system is
|
|
1762
|
+
* NOT under memory pressure.
|
|
1755
1763
|
*
|
|
1756
|
-
*
|
|
1757
|
-
*
|
|
1758
|
-
*
|
|
1759
|
-
*
|
|
1760
|
-
*
|
|
1761
|
-
*
|
|
1762
|
-
*
|
|
1763
|
-
*
|
|
1764
|
-
*
|
|
1764
|
+
* MUST match `cache-secs` and `demuxer-readahead-secs` in
|
|
1765
|
+
* `android/src/main/cpp/main.cpp` — the two places that set the
|
|
1766
|
+
* same policy, kept in step deliberately.
|
|
1767
|
+
*
|
|
1768
|
+
* 300 s is chosen so the buffered band a seek bar paints is
|
|
1769
|
+
* WIDER than the scrub thumb that sits on top of it. A 14 dp
|
|
1770
|
+
* thumb covers 3.04 % of a 230 dp rail; 300 s is 6.1 % of a
|
|
1771
|
+
* feature-length film and 120 s was only 2.44 %, so at 120 s the
|
|
1772
|
+
* thumb covered the entire visible band and the buffered
|
|
1773
|
+
* indicator could not be seen at all (measured on device
|
|
1774
|
+
* 2026-10-20: track 690 px, band 16 px, thumb half-width 21 px).
|
|
1765
1775
|
*/
|
|
1766
|
-
|
|
1776
|
+
private val baseCacheWindowSecs = 300
|
|
1777
|
+
|
|
1778
|
+
/**
|
|
1779
|
+
* Apply a cache / prefetch window to BOTH mpv options that govern it.
|
|
1780
|
+
*
|
|
1781
|
+
* mpv computes the demuxer's read-ahead target as the MAXIMUM of
|
|
1782
|
+
* the two options, not as one overriding the other:
|
|
1783
|
+
*
|
|
1784
|
+
* mpv `demux/demux.c`, `update_opts()`:
|
|
1785
|
+
* in->min_secs = opts->min_secs; // demuxer-readahead-secs
|
|
1786
|
+
* if (use_cache)
|
|
1787
|
+
* in->min_secs = MPMAX(in->min_secs, opts->min_secs_cache);
|
|
1788
|
+
* // cache-secs
|
|
1789
|
+
*
|
|
1790
|
+
* `update_opts()` re-runs on EVERY config change, so trimming only
|
|
1791
|
+
* `cache-secs` would leave `in->min_secs` pinned at the readahead
|
|
1792
|
+
* value and the trim would have NO effect at all. Both options
|
|
1793
|
+
* therefore always move together. That is a property of mpv, not a
|
|
1794
|
+
* style choice.
|
|
1795
|
+
*/
|
|
1796
|
+
private fun applyCacheWindow(seconds: Int, reason: String) {
|
|
1767
1797
|
if (nativePtr == 0L) return
|
|
1798
|
+
try {
|
|
1799
|
+
MPVLib.setPropertyString(nativePtr, "cache-secs", seconds.toString())
|
|
1800
|
+
MPVLib.setPropertyString(nativePtr, "demuxer-readahead-secs", seconds.toString())
|
|
1801
|
+
Log.w(
|
|
1802
|
+
TAG,
|
|
1803
|
+
"[PlaybackTrace][Bridge][cacheWindow] $reason → cache-secs=$seconds " +
|
|
1804
|
+
"demuxer-readahead-secs=$seconds",
|
|
1805
|
+
)
|
|
1806
|
+
} catch (e: Exception) {
|
|
1807
|
+
Log.w(TAG, "[PlaybackTrace][Bridge][cacheWindow] $reason failed: ${e.message}", e)
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
/**
|
|
1812
|
+
* System memory pressure: shrink the prefetch window.
|
|
1813
|
+
*
|
|
1814
|
+
* This module implements `ComponentCallbacks2` and is registered
|
|
1815
|
+
* with the application context in `initialize()` (and unregistered
|
|
1816
|
+
* in `onCatalystInstanceDestroy()`), so the system actually
|
|
1817
|
+
* reaches this. An earlier version of this file documented a
|
|
1818
|
+
* `PlayerActivity.onCreate` registration that did not exist, so the
|
|
1819
|
+
* handler was DEAD: the buffer was never reduced, and the
|
|
1820
|
+
* documented policy was fiction.
|
|
1821
|
+
*
|
|
1822
|
+
* Levels:
|
|
1823
|
+
* - TRIM_MEMORY_RUNNING_MODERATE (5) → 10 s
|
|
1824
|
+
* - TRIM_MEMORY_RUNNING_LOW (10) → 5 s
|
|
1825
|
+
* - TRIM_MEMORY_RUNNING_CRITICAL (15) → 2 s
|
|
1826
|
+
* - TRIM_MEMORY_BACKGROUND (40) → 10 s
|
|
1827
|
+
* - TRIM_MEMORY_COMPLETE (80) → 0 s
|
|
1828
|
+
*
|
|
1829
|
+
* A trim is a REACTION to pressure, not a new setting: loading a
|
|
1830
|
+
* file restores the base window, so the reduction is not a
|
|
1831
|
+
* permanent ratchet that leaves every later playback with a 10 s
|
|
1832
|
+
* buffer — and therefore an invisible buffered band.
|
|
1833
|
+
*/
|
|
1834
|
+
// `ComponentCallbacks2.onTrimMemory(int)` and the `TRIM_MEMORY_*`
|
|
1835
|
+
// constants carry `@Deprecated` from API 35, but this 1-arg method
|
|
1836
|
+
// is the ONLY trim callback the platform exposes — checked against
|
|
1837
|
+
// the installed android-34 / 35 / 36 / 36.1 jars, none of them has a
|
|
1838
|
+
// 2-arg overload. Implementing it is therefore the only way a
|
|
1839
|
+
// memory-pressure policy can run at all.
|
|
1840
|
+
@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION")
|
|
1841
|
+
override fun onTrimMemory(level: Int) {
|
|
1768
1842
|
val cacheSecs: Int = when (level) {
|
|
1769
1843
|
android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE -> 10
|
|
1770
1844
|
android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW -> 5
|
|
@@ -1773,12 +1847,25 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
1773
1847
|
android.content.ComponentCallbacks2.TRIM_MEMORY_COMPLETE -> 0
|
|
1774
1848
|
else -> return // unknown level — no change
|
|
1775
1849
|
}
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1850
|
+
applyCacheWindow(cacheSecs, "trim level=$level")
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
/**
|
|
1854
|
+
* `ComponentCallbacks2` also requires `onLowMemory` — the
|
|
1855
|
+
* platform's "you are about to be killed" signal. The window goes
|
|
1856
|
+
* to zero.
|
|
1857
|
+
*/
|
|
1858
|
+
@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION")
|
|
1859
|
+
override fun onLowMemory() {
|
|
1860
|
+
applyCacheWindow(0, "low memory")
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
/**
|
|
1864
|
+
* Required by `ComponentCallbacks2`. The cache window does not
|
|
1865
|
+
* depend on the configuration, so there is nothing to do.
|
|
1866
|
+
*/
|
|
1867
|
+
override fun onConfigurationChanged(newConfig: android.content.res.Configuration) {
|
|
1868
|
+
// no-op by design
|
|
1782
1869
|
}
|
|
1783
1870
|
|
|
1784
1871
|
@ReactMethod
|
|
@@ -1796,6 +1883,9 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
1796
1883
|
override fun initialize() {
|
|
1797
1884
|
super.initialize()
|
|
1798
1885
|
MPVLib.addListener(mpvListener)
|
|
1886
|
+
// Register the memory-pressure callback so `onTrimMemory` /
|
|
1887
|
+
// `onLowMemory` are actually reached by the platform.
|
|
1888
|
+
reactApplicationContext.registerComponentCallbacks(this)
|
|
1799
1889
|
// Phase 39: native module init logging. Logs the key
|
|
1800
1890
|
// properties of the bridge on init so dev tools can confirm
|
|
1801
1891
|
// the module is wired + report version/build info. Use
|
|
@@ -1811,6 +1901,7 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
1811
1901
|
override fun onCatalystInstanceDestroy() {
|
|
1812
1902
|
destroy()
|
|
1813
1903
|
MPVLib.removeListener(mpvListener)
|
|
1904
|
+
reactApplicationContext.unregisterComponentCallbacks(this)
|
|
1814
1905
|
// Phase 36: clear the static ReactApplicationContext reference so the
|
|
1815
1906
|
// bridge context can be reclaimed. Companion-level static fields hold
|
|
1816
1907
|
// the only strong reference to the React context across reloads;
|
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.20.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",
|
|
@@ -504,7 +504,7 @@ export interface MpvPlayerModuleBridge {
|
|
|
504
504
|
|
|
505
505
|
// ── Picture-in-Picture ─────────────────────────────────────────────────
|
|
506
506
|
/** Enter PiP mode; optional chapter title + progress percent for notification. */
|
|
507
|
-
enterPip(chapterTitle?: string, progressPct?: string): void;
|
|
507
|
+
enterPip(chapterTitle?: string | null, progressPct?: string | null): void;
|
|
508
508
|
/** Exit PiP by bringing the activity to the front. */
|
|
509
509
|
exitPip(): void;
|
|
510
510
|
/** Exit PiP and finish the activity. */
|
|
@@ -313,7 +313,14 @@ export interface Spec extends TurboModule {
|
|
|
313
313
|
// Two declarations of one method, disagreeing, is the same class of
|
|
314
314
|
// defect as the MediaKind/MediaLane confusion: the real bug is that
|
|
315
315
|
// there are two sources of truth, not that either value was wrong.
|
|
316
|
-
|
|
316
|
+
//
|
|
317
|
+
// They are declared REQUIRED and nullable here, because that is what
|
|
318
|
+
// the TurboModule boundary actually is: the method has arity 2 and
|
|
319
|
+
// TurboModule checks the argument count on every call. Writing `?`
|
|
320
|
+
// here said "you may call this with no arguments", which is exactly
|
|
321
|
+
// the licence the zero-argument call site took — and the crash it
|
|
322
|
+
// produced was an "expected argument count: 2" rejection.
|
|
323
|
+
enterPip(chapterTitle: string | null, progressPct: string | null): void;
|
|
317
324
|
exitPip(): void;
|
|
318
325
|
exitPipAndFinish(): void;
|
|
319
326
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The PiP command must call the native bridge with TWO arguments.
|
|
3
|
+
*
|
|
4
|
+
* The native TurboModule method has arity 2, and TurboModule checks the
|
|
5
|
+
* argument count on EVERY call, so a zero-argument call is rejected
|
|
6
|
+
* before it ever reaches the native body:
|
|
7
|
+
*
|
|
8
|
+
* Exception in HostFunction: TurboModule method "enterPip"
|
|
9
|
+
* called with 0 arguments (expected argument count: 2)
|
|
10
|
+
*
|
|
11
|
+
* That is what the PiP button did: it threw instead of entering PiP.
|
|
12
|
+
* The native side had already been made nullable (v1.9.3) and the
|
|
13
|
+
* codegen spec had already been given two parameters — but the CALL
|
|
14
|
+
* SITE still passed none, and nothing tested the call site's arity.
|
|
15
|
+
*
|
|
16
|
+
* So this file asserts the arity, not the behaviour: a test that only
|
|
17
|
+
* checked "enterPip was called" would pass with a zero-argument call
|
|
18
|
+
* and the bug would survive.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import {NativeModules} from 'react-native';
|
|
22
|
+
import {renderHook} from '@testing-library/react-native';
|
|
23
|
+
import {usePlayer} from '../player';
|
|
24
|
+
|
|
25
|
+
function enterPipMock(): jest.Mock {
|
|
26
|
+
return (NativeModules.MpvPlayerModule as unknown as Record<string, jest.Mock>)
|
|
27
|
+
.enterPip;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('commands.enterPip — the native call arity', () => {
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
for (const key of Object.keys(NativeModules.MpvPlayerModule)) {
|
|
33
|
+
const fn = (NativeModules.MpvPlayerModule as unknown as Record<
|
|
34
|
+
string,
|
|
35
|
+
jest.Mock
|
|
36
|
+
>)[key];
|
|
37
|
+
if (typeof fn?.mockClear === 'function') {
|
|
38
|
+
fn.mockClear();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('calls the bridge with TWO arguments even when no values are given', async () => {
|
|
44
|
+
const {result} = await renderHook(() => usePlayer());
|
|
45
|
+
result.current.commands.enterPip();
|
|
46
|
+
|
|
47
|
+
const enterPip = enterPipMock();
|
|
48
|
+
expect(enterPip).toHaveBeenCalledTimes(1);
|
|
49
|
+
// The arity is the whole point: TurboModule rejects anything else.
|
|
50
|
+
expect(enterPip.mock.calls[0]).toHaveLength(2);
|
|
51
|
+
// And the "not supplied" value is null, which the native accepts
|
|
52
|
+
// (its own fallbacks are "Simba Player" and "0 %").
|
|
53
|
+
expect(enterPip.mock.calls[0][0]).toBeNull();
|
|
54
|
+
expect(enterPip.mock.calls[0][1]).toBeNull();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('forwards the chapter title and the progress percentage', async () => {
|
|
58
|
+
const {result} = await renderHook(() => usePlayer());
|
|
59
|
+
result.current.commands.enterPip('Chapter 3', '45 %');
|
|
60
|
+
|
|
61
|
+
const enterPip = enterPipMock();
|
|
62
|
+
expect(enterPip.mock.calls[0]).toHaveLength(2);
|
|
63
|
+
expect(enterPip).toHaveBeenCalledWith('Chapter 3', '45 %');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('passes null for a value that was not supplied, not undefined', async () => {
|
|
67
|
+
const {result} = await renderHook(() => usePlayer());
|
|
68
|
+
result.current.commands.enterPip('Chapter 3', null);
|
|
69
|
+
|
|
70
|
+
const enterPip = enterPipMock();
|
|
71
|
+
expect(enterPip.mock.calls[0]).toHaveLength(2);
|
|
72
|
+
expect(enterPip).toHaveBeenCalledWith('Chapter 3', null);
|
|
73
|
+
});
|
|
74
|
+
});
|
package/src/types/player.ts
CHANGED
|
@@ -279,8 +279,16 @@ export interface PlayerCommands {
|
|
|
279
279
|
setTrack(type: 'video' | 'audio' | 'sub', trackId: number): void;
|
|
280
280
|
|
|
281
281
|
// PiP
|
|
282
|
-
/**
|
|
283
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Enter Picture-in-Picture mode.
|
|
284
|
+
*
|
|
285
|
+
* `chapterTitle` and `progressPct` are shown in the PiP notification.
|
|
286
|
+
* They are optional HERE, but the native TurboModule method takes two
|
|
287
|
+
* arguments and TurboModule enforces its arity — so the bridge call
|
|
288
|
+
* always passes two, never zero. See `enterPip` in the command
|
|
289
|
+
* implementation below.
|
|
290
|
+
*/
|
|
291
|
+
enterPip(chapterTitle?: string | null, progressPct?: string | null): void;
|
|
284
292
|
/** Exit PiP by bringing the activity to the front. */
|
|
285
293
|
exitPip(): void;
|
|
286
294
|
/** Exit PiP and finish the activity. */
|
|
@@ -685,9 +693,18 @@ function buildCommands(): PlayerCommands {
|
|
|
685
693
|
getMpvPlayerModule().setTrack(type, trackId);
|
|
686
694
|
},
|
|
687
695
|
|
|
688
|
-
enterPip: () => {
|
|
689
|
-
dlog('commands.enterPip()');
|
|
690
|
-
|
|
696
|
+
enterPip: (chapterTitle, progressPct) => {
|
|
697
|
+
dlog('commands.enterPip(', chapterTitle, ',', progressPct, ')');
|
|
698
|
+
// The native method has arity 2 and TurboModule ENFORCES it, so
|
|
699
|
+
// this call must always pass two arguments. Passing zero threw:
|
|
700
|
+
//
|
|
701
|
+
// Exception in HostFunction: TurboModule method "enterPip"
|
|
702
|
+
// called with 0 arguments (expected argument count: 2)
|
|
703
|
+
//
|
|
704
|
+
// The Kotlin side is nullable, so `null` is the right "not
|
|
705
|
+
// supplied" value — the native falls back to a title and a
|
|
706
|
+
// progress string of its own.
|
|
707
|
+
getMpvPlayerModule().enterPip(chapterTitle ?? null, progressPct ?? null);
|
|
691
708
|
},
|
|
692
709
|
exitPip: () => {
|
|
693
710
|
dlog('commands.exitPip()');
|