@simba-dev/react-native-media-player 1.9.2 → 1.9.4

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.
@@ -512,15 +512,45 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
512
512
  @ReactMethod
513
513
  @Override
514
514
  override fun setOrientation(mode: String) {
515
- val activity = getCurrentActivity() ?: return
515
+ val activity = getCurrentActivity()
516
+ if (activity == null) {
517
+ // v1.9.3 — this used to be a bare `?: return`. That is a
518
+ // silent no-op: the JS side flips its "locked" flag, the
519
+ // glyph swaps to a padlock, and the video keeps rotating as
520
+ // if nothing was requested. A control that reports success
521
+ // while doing nothing is worse than one that errors, so the
522
+ // refusal is logged at the same level the caller can find.
523
+ android.util.Log.w(TAG, "setOrientation('$mode') ignored: no current activity")
524
+ return
525
+ }
516
526
  activity.runOnUiThread {
517
527
  val requested = when (mode.lowercase()) {
518
- "portrait" -> android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
519
- "landscape" -> android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
528
+ // v1.9.3 — these were USER_PORTRAIT / USER_LANDSCAPE.
529
+ //
530
+ // The `USER_` variants respect the SYSTEM auto-rotate
531
+ // switch: with auto-rotate off, asking for landscape is
532
+ // silently ignored by the platform. That is exactly the
533
+ // reported symptom — tap the lock, the glyph changes,
534
+ // the video does not move.
535
+ //
536
+ // An app asking to PIN the window is making an explicit
537
+ // user decision about this one activity, so it must win
538
+ // over a global device preference. The plain constants
539
+ // are the correct ones for an explicit per-activity
540
+ // request.
541
+ "portrait" -> android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
542
+ "landscape" -> android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
543
+ // 'sensor' is the opposite case: it MEANS "follow the
544
+ // device", so honouring the user's rotation lock is the
545
+ // point of the mode, and FULL_SENSOR already does that.
520
546
  "sensor" -> android.content.pm.ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
521
547
  else -> android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
522
548
  }
523
549
  activity.requestedOrientation = requested
550
+ android.util.Log.d(
551
+ TAG,
552
+ "setOrientation('$mode') -> requestedOrientation=$requested (was ${activity.requestedOrientation})",
553
+ )
524
554
  }
525
555
  }
526
556
 
@@ -1591,15 +1621,33 @@ class MpvBridgeModule(reactContext: ReactApplicationContext) :
1591
1621
  */
1592
1622
  @ReactMethod
1593
1623
  @Override
1594
- override fun enterPip(chapterTitle: String, progressPct: String) {
1624
+ override fun enterPip(chapterTitle: String?, progressPct: String?) {
1595
1625
  val activity = getCurrentActivity()
1596
1626
  if (activity == null || android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N) return
1627
+ // v1.9.3 — SPEC invariant I7 (a TS signature must agree with the
1628
+ // native reality it forwards to).
1629
+ //
1630
+ // These two params were declared `String` (non-null, REQUIRED)
1631
+ // while `MpvPlayerModule.ts` declares them optional. TurboModule
1632
+ // enforces the KOTLIN arity, so the JS call
1633
+ // `enterPip()` with zero arguments was rejected before it ever
1634
+ // reached this body:
1635
+ //
1636
+ // Exception in HostFunction: TurboModule method "enterPip"
1637
+ // called with 0 arguments (expected argument count: 2)
1638
+ //
1639
+ // The Kotlin side is now nullable, which is what the TS contract
1640
+ // has always claimed, so both zero-arg and two-arg calls are
1641
+ // legal. The defaults below keep the PiP notification useful
1642
+ // rather than blank.
1643
+ val title = chapterTitle?.takeIf { it.isNotBlank() } ?: "Simba Player"
1644
+ val pct = progressPct?.takeIf { it.isNotBlank() } ?: "0 %"
1597
1645
  try {
1598
1646
  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
1599
1647
  val pipParams = com.simba.player.PipManager.buildPipParams(
1600
1648
  context = activity,
1601
- chapterTitle = chapterTitle,
1602
- progressPercentage = progressPct,
1649
+ chapterTitle = title,
1650
+ progressPercentage = pct,
1603
1651
  )
1604
1652
  activity.enterPictureInPictureMode(pipParams)
1605
1653
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simba-dev/react-native-media-player",
3
- "version": "1.9.2",
3
+ "version": "1.9.4",
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",
@@ -69,11 +69,34 @@ const SIGNATURE_NORMALIZATIONS = [
69
69
  pattern: / val resolvedTitle = title\?\.takeIf \{ it\.isNotBlank\(\) \} \?: uri/,
70
70
  replacement: " val resolvedTitle = title.takeIf { it.isNotBlank() } ?: uri",
71
71
  },
72
- // 3. enterPip: drop nullable types + defaults
72
+ // 3. enterPip — v1.9.3: THE NORMALIZATION IS GONE.
73
+ //
74
+ // It used to rewrite
75
+ // fun enterPip(chapterTitle: String? = null, progressPct: String? = null)
76
+ // into
77
+ // fun enterPip(chapterTitle: String, progressPct: String)
78
+ // on the stated grounds that "the spec is non-null, no defaults".
79
+ //
80
+ // That was the cause of a hard crash, not a compatibility fix.
81
+ // TurboModule enforces the KOTLIN arity, and the TypeScript contract
82
+ // has always declared both params optional, so `enterPip()` from JS
83
+ // was rejected before it reached the method body:
84
+ //
85
+ // Exception in HostFunction: TurboModule method "enterPip"
86
+ // called with 0 arguments (expected argument count: 2)
87
+ //
88
+ // The nullability is now KEPT (that is what codegen produces from
89
+ // `MpvPlayerModule.ts`), which makes both zero-arg and two-arg calls
90
+ // legal. This rule used to throw if it matched zero times, so it
91
+ // could not simply be left in place: re-running this script would
92
+ // have failed the build with a confusing "did not match exactly once"
93
+ // rather than silently reverting the fix. Kept here as an
94
+ // assertion instead, so a re-run PROVES the signature is still the
95
+ // fixed one and fails loudly if someone reintroduces the bug.
73
96
  {
74
- name: "enterPip-signature",
75
- pattern: / fun enterPip\(chapterTitle: String\? = null, progressPct: String\? = null\) \{/,
76
- replacement: " fun enterPip(chapterTitle: String, progressPct: String) {",
97
+ name: "enterPip-signature-guard",
98
+ pattern: / override fun enterPip\(chapterTitle: String\?, progressPct: String\?\) \{/,
99
+ replacement: " override fun enterPip(chapterTitle: String?, progressPct: String?) {",
77
100
  },
78
101
  ];
79
102
 
@@ -752,6 +752,42 @@ export function getMpvPlayerModule(): MpvPlayerModuleBridge {
752
752
  return bridge;
753
753
  }
754
754
 
755
+ /**
756
+ * v1.9.3 — override the media title mpv will report, BEFORE the file is
757
+ * loaded.
758
+ *
759
+ * mpv derives `media-title` from the container's metadata tags, falling
760
+ * back to the URL's last path segment. Neither is usable for a streaming
761
+ * catalogue: a signed CDN URL ends in something like
762
+ * `abc123?sig=…&exp=…`, so an un-overridden player header shows that
763
+ * token. `force-media-title` is mpv's own option for replacing it.
764
+ *
765
+ * Two things are load-bearing here:
766
+ *
767
+ * 1. **Ordering.** The option is read at load time, so this must run
768
+ * before `loadFile`. Callers that put it after would leave the
769
+ * already-loaded file with mpv's derived title.
770
+ * 2. **Not throwing.** A rejected property write must never abort the
771
+ * load — the video matters more than its title, and mpv falls back
772
+ * to deriving one. It is warned about instead, because a silent
773
+ * failure here is a wrong title that nobody can explain.
774
+ *
775
+ * Shared by `commands.loadFile` and `useLaunchPlayback`, which are two
776
+ * genuinely different entry points (`openPlayer` → activity → launch
777
+ * params versus a direct programmatic load) and would otherwise each
778
+ * re-implement the set-then-load ordering.
779
+ */
780
+ export function applyForceMediaTitle(bridge: MpvPlayerModuleBridge, title?: string): void {
781
+ const trimmed = title?.trim();
782
+ if (!trimmed) return;
783
+ try {
784
+ bridge.setProperty('force-media-title', trimmed);
785
+ } catch (e) {
786
+ // eslint-disable-next-line no-console
787
+ console.warn('[simba-player] force-media-title rejected:', e);
788
+ }
789
+ }
790
+
755
791
  /**
756
792
  * V13 Phase 50c: subscribe to a native event. Returns an
757
793
  * unsubscribe function that callers should invoke from
@@ -300,6 +300,22 @@ const OBSERVED_PROPERTIES: readonly string[] = [
300
300
  'paused-for-cache',
301
301
  'cache-buffering-state',
302
302
  'demuxer-cache-state',
303
+ // v1.9.3 — `media-title` and `metadata` were MISSING here.
304
+ //
305
+ // `PlayerState.title` is documented as coming from mpv `media-title`,
306
+ // and `applyPlayerEvent` really does handle `case 'media-title'` and
307
+ // `case 'metadata'` — but mpv only emits MPV_EVENT_PROPERTY_CHANGE for
308
+ // names that were passed to `mpv_observe_property`, and neither of
309
+ // these two was. So the handlers existed, the documentation was
310
+ // specific, and the title never left the native layer: every player
311
+ // header rendered the `DEFAULT_STATE` placeholder "Simba Player".
312
+ //
313
+ // Same defect class as the `mute` gap below and the `seekable` gap
314
+ // above: a correctly-written handler wired to a property nobody
315
+ // registered. Invisible to the test suite, which mocks the emitter.
316
+ // The assertion that catches it is on THIS LIST, not on the handler.
317
+ 'media-title',
318
+ 'metadata',
303
319
  // V19 W8.3.1 — `mute` was MISSING from this list, and its absence was
304
320
  // invisible in every test because the whole emitter is mocked.
305
321
  //
@@ -332,6 +332,17 @@ describe('mpv property observation', () => {
332
332
  'paused-for-cache',
333
333
  'demuxer-cache-state',
334
334
  'mute',
335
+ // v1.9.3 — the title gap. `PlayerState.title` is documented as
336
+ // coming from mpv `media-title`, and `applyPlayerEvent` handles
337
+ // both `case 'media-title'` and `case 'metadata'` — but neither
338
+ // name was ever registered, so no event could ever arrive and
339
+ // every consumer rendered the DEFAULT_STATE placeholder
340
+ // "Simba Player" regardless of what was playing.
341
+ //
342
+ // Mutation-check: comment either line out and this assertion is
343
+ // the thing that fails.
344
+ 'media-title',
345
+ 'metadata',
335
346
  ]),
336
347
  );
337
348
 
@@ -117,6 +117,73 @@ describe('useLaunchPlayback', () => {
117
117
  render(<Harness params={undefined} />);
118
118
  await waitFor(() => expect(bridge().loadFile).not.toHaveBeenCalled());
119
119
  });
120
+
121
+ // ── v1.9.3: the title the launch payload always carried ──────────────
122
+ //
123
+ // `LaunchParams.title` has always existed and has always come straight
124
+ // from the host app's `openPlayer({uri, title})`. This hook — the ONE
125
+ // place that actually loads the file — read `uri` and
126
+ // `startPositionMs` and discarded it. With `media-title` also unobserved,
127
+ // `PlayerState.title` stayed at the DEFAULT_STATE placeholder and every
128
+ // player header rendered the literal string "Simba Player".
129
+ //
130
+ // This is the path the app actually takes (`openPlayer` → activity →
131
+ // launch params → this hook), which is why it is the assertion that
132
+ // matters, not just the one on `commands.loadFile`.
133
+
134
+ it('applies the launch title as mpv force-media-title before loading', async () => {
135
+ render(<Harness params={{...PARAMS, title: 'Overrun!'}} />);
136
+ await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
137
+ expect(bridge().setProperty).toHaveBeenCalledWith(
138
+ 'force-media-title',
139
+ 'Overrun!',
140
+ );
141
+ });
142
+
143
+ it('sets the title BEFORE the load — mpv reads the option at load time', async () => {
144
+ const order: string[] = [];
145
+ bridge().setProperty.mockImplementation(() => {
146
+ order.push('setProperty');
147
+ });
148
+ bridge().loadFile.mockImplementation(() => {
149
+ order.push('loadFile');
150
+ });
151
+
152
+ render(<Harness params={{...PARAMS, title: 'Overrun!'}} />);
153
+ await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
154
+ expect(order).toEqual(['setProperty', 'loadFile']);
155
+ });
156
+
157
+ it('trims the launch title', async () => {
158
+ render(<Harness params={{...PARAMS, title: ' Overrun! '}} />);
159
+ await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
160
+ expect(bridge().setProperty).toHaveBeenCalledWith(
161
+ 'force-media-title',
162
+ 'Overrun!',
163
+ );
164
+ });
165
+
166
+ it('omits the option when the title is blank — mpv keeps deriving its own', async () => {
167
+ // Writing an empty `force-media-title` would BLANK the header, which
168
+ // is worse than the derived fallback it replaced.
169
+ render(<Harness params={{...PARAMS, title: ' '}} />);
170
+ await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
171
+ expect(bridge().setProperty).not.toHaveBeenCalledWith(
172
+ 'force-media-title',
173
+ expect.anything(),
174
+ );
175
+ });
176
+
177
+ it('still loads the file when the title write is rejected', async () => {
178
+ // A rejected option must never cost the user their video.
179
+ bridge().setProperty.mockImplementationOnce(() => {
180
+ throw new Error('property rejected');
181
+ });
182
+
183
+ render(<Harness params={{...PARAMS, title: 'Overrun!'}} />);
184
+ await waitFor(() => expect(bridge().loadFile).toHaveBeenCalledTimes(1));
185
+ expect(bridge().play).toHaveBeenCalledTimes(1);
186
+ });
120
187
  });
121
188
 
122
189
  describe('SimbaPlayerRoot — headless', () => {
@@ -1,5 +1,9 @@
1
1
  import { useEffect } from 'react';
2
- import { getMpvPlayerModule, type LaunchParams } from '../bridge/MpvPlayerModule';
2
+ import {
3
+ applyForceMediaTitle,
4
+ getMpvPlayerModule,
5
+ type LaunchParams,
6
+ } from '../bridge/MpvPlayerModule';
3
7
 
4
8
  /**
5
9
  * Feed a launch payload to mpv, exactly once per payload.
@@ -44,6 +48,7 @@ export function useLaunchPlayback(
44
48
  launchParams: LaunchParams | null | undefined,
45
49
  ): void {
46
50
  const uri = launchParams?.uri ?? null;
51
+ const title = launchParams?.title ?? undefined;
47
52
  const startPositionSec = launchParams?.startPositionMs
48
53
  ? launchParams.startPositionMs / 1000
49
54
  : 0;
@@ -55,6 +60,15 @@ export function useLaunchPlayback(
55
60
  }
56
61
  const bridge = getMpvPlayerModule();
57
62
  try {
63
+ // v1.9.3 — `launchParams.title` was READ BY NOTHING here. The
64
+ // launch payload has always carried the real title (it comes
65
+ // straight from the host app's `openPlayer({uri, title})`), and
66
+ // this hook — the one place that actually loads the file — threw
67
+ // it away. Combined with `media-title` never being observed, that
68
+ // is why every player header read "Simba Player".
69
+ //
70
+ // Must precede `loadFile`: mpv reads the option at load time.
71
+ applyForceMediaTitle(bridge, title);
58
72
  bridge.loadFile(uri);
59
73
  if (startPositionSec > 0) {
60
74
  bridge.seekAbsolute(startPositionSec);
@@ -783,3 +783,205 @@ describe('commands that route through setProperty', () => {
783
783
  );
784
784
  });
785
785
  });
786
+
787
+ describe('PlayerState.title comes from mpv media-title (v1.9.3)', () => {
788
+ // The other half of the fix. Registering `media-title` only matters if
789
+ // a `media-title` event actually moves `state.title` — and the reason
790
+ // the header said "Simba Player" is that neither half was in place:
791
+ // the property was never registered, so the event never arrived.
792
+ const wrapper = ({ children }: { children: React.ReactNode }) => (
793
+ <PlayerProvider>{children}</PlayerProvider>
794
+ );
795
+
796
+ let subs: ReturnType<typeof captureSubscribes>;
797
+ beforeEach(() => {
798
+ clearBridgeMocks();
799
+ subs = captureSubscribes();
800
+ });
801
+ afterEach(() => {
802
+ subs.restore();
803
+ });
804
+
805
+ it('starts at the placeholder, so a passing test below is meaningful', async () => {
806
+ const { result } = await renderHook(() => usePlayer(), { wrapper });
807
+ expect(result.current.state.title).toBe('Simba Player');
808
+ });
809
+
810
+ it('adopts a media-title property change', async () => {
811
+ const { result } = await renderHook(() => usePlayer(), { wrapper });
812
+ const listeners = subs.handlers.get('onPropertyChanged') ?? [];
813
+ expect(listeners.length).toBeGreaterThan(0);
814
+
815
+ await act(async () => {
816
+ for (const l of listeners) {
817
+ l({property: 'media-title', value: 'Overrun!'});
818
+ }
819
+ });
820
+
821
+ expect(result.current.state.title).toBe('Overrun!');
822
+ });
823
+
824
+ it('adopts the title embedded in a metadata property change', async () => {
825
+ const { result } = await renderHook(() => usePlayer(), { wrapper });
826
+ const listeners = subs.handlers.get('onPropertyChanged') ?? [];
827
+
828
+ // mpv's `metadata` is a NODE LIST, so it arrives as an array of
829
+ // {key, value} entries — not as a flat object. `parseMetadata`
830
+ // correctly rejects a flat object with `{}`; the first draft of
831
+ // this test sent one and failed, which is the test having been
832
+ // wrong rather than the parser being loose.
833
+ await act(async () => {
834
+ for (const l of listeners) {
835
+ l({
836
+ property: 'metadata',
837
+ value: JSON.stringify([
838
+ {key: 'title', value: 'Overrun!'},
839
+ {key: 'artist', value: 'Monica Strebel'},
840
+ ]),
841
+ });
842
+ }
843
+ });
844
+
845
+ expect(result.current.state.title).toBe('Overrun!');
846
+ expect(result.current.state.artist).toBe('Monica Strebel');
847
+ });
848
+
849
+ it('never adopts mpv\'s "null" sentinel as the title', async () => {
850
+ // mpv serialises a null string as the four-character literal
851
+ // "null" across the JSON boundary. Assigning it produces a header
852
+ // reading literally `null` — a regression this codebase has already
853
+ // been bitten by once (D-035).
854
+ const { result } = await renderHook(() => usePlayer(), { wrapper });
855
+ const listeners = subs.handlers.get('onPropertyChanged') ?? [];
856
+
857
+ await act(async () => {
858
+ for (const l of listeners) {
859
+ l({property: 'media-title', value: 'null'});
860
+ }
861
+ });
862
+
863
+ expect(result.current.state.title).toBe('Simba Player');
864
+ });
865
+
866
+ it('adopts a real title that arrives after the placeholder was replaced', async () => {
867
+ // Switching items must not leave the previous item's title behind.
868
+ const { result } = await renderHook(() => usePlayer(), { wrapper });
869
+ const listeners = subs.handlers.get('onPropertyChanged') ?? [];
870
+
871
+ await act(async () => {
872
+ for (const l of listeners) {
873
+ l({property: 'media-title', value: 'First film'});
874
+ }
875
+ });
876
+ await act(async () => {
877
+ for (const l of listeners) {
878
+ l({property: 'media-title', value: 'Second film'});
879
+ }
880
+ });
881
+
882
+ expect(result.current.state.title).toBe('Second film');
883
+ });
884
+ });
885
+
886
+ /**
887
+ * v1.9.3 — the title that was accepted and thrown away.
888
+ *
889
+ * `openPlayer({uri, title})` has always accepted a title, and it has
890
+ * always reached `PlayerActivity`. What never happened was anyone
891
+ * APPLYING it:
892
+ *
893
+ * - `useLaunchPlayback` destructures only `uri` and `startPositionMs`
894
+ * out of the launch params, then calls `loadFile(uri)`;
895
+ * - `onFileLoaded`'s handler reads `file?.title` from a native payload
896
+ * that contains `requestId` and `resolvedPath` and no `file` key, so
897
+ * the branch never fired;
898
+ * - `media-title` and `metadata` were absent from OBSERVED_PROPERTIES,
899
+ * so mpv's own title could not arrive either.
900
+ *
901
+ * The net effect for every consumer was `PlayerState.title` pinned at the
902
+ * `DEFAULT_STATE` placeholder, and a player header reading "Simba
903
+ * Player" over whatever film was actually playing.
904
+ *
905
+ * The fix applies mpv's own `force-media-title` option BEFORE the load.
906
+ */
907
+ describe('commands.loadFile applies the launch title (v1.9.3)', () => {
908
+ beforeEach(() => {
909
+ clearBridgeMocks();
910
+ });
911
+
912
+ it('writes force-media-title with the supplied title', async () => {
913
+ const { result } = await renderHook(() => usePlayer());
914
+ await result.current.commands.loadFile('file:///a.mp4', 'Overrun!');
915
+ expect(NativeModules.MpvPlayerModule.setProperty).toHaveBeenCalledWith(
916
+ 'force-media-title',
917
+ 'Overrun!',
918
+ );
919
+ });
920
+
921
+ it('sets the option BEFORE loading, because mpv applies it at load time', async () => {
922
+ // Order is the contract, not an optimisation. `force-media-title`
923
+ // is read when the file is loaded, so setting it afterwards would
924
+ // leave the already-loaded file with mpv's derived title — which
925
+ // for a signed CDN URL is an opaque token, not a movie name.
926
+ const { result } = await renderHook(() => usePlayer());
927
+ await result.current.commands.loadFile('file:///a.mp4', 'Overrun!');
928
+
929
+ const order: string[] = [];
930
+ const setProperty = NativeModules
931
+ .MpvPlayerModule.setProperty as jest.Mock;
932
+ const loadFile = NativeModules.MpvPlayerModule.loadFile as jest.Mock;
933
+ setProperty.mockImplementation(() => {
934
+ order.push('setProperty');
935
+ });
936
+ loadFile.mockImplementation(() => {
937
+ order.push('loadFile');
938
+ });
939
+
940
+ await result.current.commands.loadFile('file:///b.mp4', 'Second');
941
+ expect(order).toEqual(['setProperty', 'loadFile']);
942
+ });
943
+
944
+ it('trims the title — a blank or padded value would render as whitespace', async () => {
945
+ const { result } = await renderHook(() => usePlayer());
946
+ await result.current.commands.loadFile('file:///a.mp4', ' Overrun! ');
947
+ expect(NativeModules.MpvPlayerModule.setProperty).toHaveBeenCalledWith(
948
+ 'force-media-title',
949
+ 'Overrun!',
950
+ );
951
+ });
952
+
953
+ it('omits the option entirely when no title is supplied', async () => {
954
+ // No title means "let mpv derive one", which is the pre-1.9.3
955
+ // behaviour. Writing `force-media-title` with an empty string would
956
+ // blank the header instead of falling back.
957
+ const { result } = await renderHook(() => usePlayer());
958
+ await result.current.commands.loadFile('file:///a.mp4');
959
+ expect(NativeModules.MpvPlayerModule.setProperty).not.toHaveBeenCalledWith(
960
+ 'force-media-title',
961
+ expect.anything(),
962
+ );
963
+ expect(NativeModules.MpvPlayerModule.loadFile).toHaveBeenCalledWith(
964
+ 'file:///a.mp4',
965
+ );
966
+ });
967
+
968
+ it('still loads the file when the property write is rejected', async () => {
969
+ // A rejected `force-media-title` must not cost the user their video.
970
+ // The video plays; the title falls back to whatever mpv derives.
971
+ const setProperty = NativeModules.MpvPlayerModule
972
+ .setProperty as jest.Mock;
973
+ setProperty.mockImplementationOnce(() => {
974
+ throw new Error('property rejected');
975
+ });
976
+
977
+ const { result } = await renderHook(() => usePlayer());
978
+ // `loadFile` is a SYNCHRONOUS command (void), so it throws rather
979
+ // than rejecting — asserting "does not throw" is the contract.
980
+ expect(() =>
981
+ result.current.commands.loadFile('file:///a.mp4', 'Overrun!'),
982
+ ).not.toThrow();
983
+ expect(NativeModules.MpvPlayerModule.loadFile).toHaveBeenCalledWith(
984
+ 'file:///a.mp4',
985
+ );
986
+ });
987
+ });
@@ -8,6 +8,7 @@ import {
8
8
  MpvVideoParams,
9
9
  MpvPlaybackState,
10
10
  MpvFileInfo,
11
+ applyForceMediaTitle,
11
12
  } from '../bridge/MpvPlayerModule';
12
13
 
13
14
  /**
@@ -185,8 +186,15 @@ export interface PlayerCommands {
185
186
  setLoopMode(mode: MpvLoopMode): void;
186
187
 
187
188
  // File loading
188
- /** Load a single media file. */
189
- loadFile(uri: string): void;
189
+ /**
190
+ * Load a single media file.
191
+ *
192
+ * `title` (v1.9.3) is applied as mpv's `force-media-title` BEFORE the
193
+ * load, so `media-title` — and therefore `PlayerState.title` — carries
194
+ * the real name of the media rather than a URL fragment. Omit it and
195
+ * mpv derives its own title as before.
196
+ */
197
+ loadFile(uri: string, title?: string): void;
190
198
  /** Load a playlist of media files, starting at `startIndex` (default 0). */
191
199
  loadPlaylist(uris: string[], startIndex?: number): void;
192
200
 
@@ -551,7 +559,19 @@ function buildCommands(): PlayerCommands {
551
559
  getMpvPlayerModule().setLoopMode(mode);
552
560
  },
553
561
 
554
- loadFile: (uri: string) => {
562
+ loadFile: (uri: string, title?: string) => {
563
+ // v1.9.3 — the launch TITLE is applied here, and this is the fix
564
+ // for a long-standing defect: `openPlayer({uri, title})` accepted a
565
+ // title and handed it to `PlayerActivity`, and then NOTHING ever
566
+ // applied it. `onFileLoaded`'s handler reads `file?.title` from a
567
+ // native payload that has no `file` key, and `media-title` was
568
+ // missing from OBSERVED_PROPERTIES — so `PlayerState.title` stayed
569
+ // pinned at the `DEFAULT_STATE` placeholder and every consumer
570
+ // rendered "Simba Player" no matter what was playing.
571
+ //
572
+ // `force-media-title` is mpv's own option for exactly this. The
573
+ // set-then-load ordering is the contract — see the helper.
574
+ applyForceMediaTitle(getMpvPlayerModule(), title);
555
575
  dlog('commands.loadFile(', uri, ')');
556
576
  getMpvPlayerModule().loadFile(uri);
557
577
  },
@@ -1052,8 +1072,24 @@ export function applyPlayerEvent(
1052
1072
  const property = String(p.property ?? '');
1053
1073
  const value = p.value;
1054
1074
  switch (property) {
1055
- case 'media-title':
1056
- return { state: { ...state, title: String(value ?? '') }, progress };
1075
+ case 'media-title': {
1076
+ // v1.9.3 — this adopted ANY value, including mpv's "no title"
1077
+ // sentinel.
1078
+ //
1079
+ // A null string crosses the JSON boundary as the FOUR-CHARACTER
1080
+ // LITERAL "null", so `String(value ?? '')` produced a player
1081
+ // header reading `null` — the same regression D-035 already
1082
+ // fixed on the `onFileLoaded` path, which filters it there. The
1083
+ // property path never got the same guard, so registering
1084
+ // `media-title` (1.9.3) would have traded one wrong title for
1085
+ // another.
1086
+ //
1087
+ // The rule is the same on both paths: an unrecognised title
1088
+ // leaves the field alone rather than replacing a good one.
1089
+ const title = String(value ?? '');
1090
+ if (!title || title === 'null') break;
1091
+ return { state: { ...state, title }, progress };
1092
+ }
1057
1093
  case 'volume':
1058
1094
  return { state: { ...state, volume: Number(value) }, progress };
1059
1095
  case 'mute':