@simba-dev/react-native-media-player 1.9.3 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simba-dev/react-native-media-player",
3
- "version": "1.9.3",
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",
@@ -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
@@ -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);
@@ -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
  /**
@@ -561,36 +562,16 @@ function buildCommands(): PlayerCommands {
561
562
  loadFile: (uri: string, title?: string) => {
562
563
  // v1.9.3 — the launch TITLE is applied here, and this is the fix
563
564
  // for a long-standing defect: `openPlayer({uri, title})` accepted a
564
- // title, handed it to `PlayerActivity`, and then NOTHING ever
565
- // applied it. `useLaunchPlayback` destructures only `uri` and
566
- // `startPositionMs` out of the launch params, `onFileLoaded`'s
567
- // handler reads `file?.title` from a native payload that has no
568
- // `file` key at all, and `media-title` was missing from
569
- // OBSERVED_PROPERTIES — so `PlayerState.title` stayed pinned at the
570
- // `DEFAULT_STATE` placeholder and every consumer rendered the
571
- // string "Simba Player" no matter what was playing.
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.
572
571
  //
573
- // `force-media-title` is mpv's own option for exactly this: it
574
- // OVERRIDES the title mpv would otherwise derive from the
575
- // container's metadata or the URL's last path segment (which, for
576
- // a signed CDN URL, is an opaque token like "abc123?sig=...").
577
- //
578
- // It has to be set BEFORE the load, so the order below is load
579
- // bearing and is not an optimisation: set, then load. Both calls
580
- // are plain `@ReactMethod`s, which the bridge dispatches in call
581
- // order, so the ordering holds.
582
- if (title && title.trim()) {
583
- try {
584
- getMpvPlayerModule().setProperty('force-media-title', title.trim());
585
- } catch (e) {
586
- // A rejected property write must not abort the load — the
587
- // video is the priority, and mpv will fall back to deriving
588
- // its own title. Surfaced loudly in dev because it means the
589
- // title will be wrong.
590
- // eslint-disable-next-line no-console
591
- console.warn('[simba-player] force-media-title rejected:', e);
592
- }
593
- }
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);
594
575
  dlog('commands.loadFile(', uri, ')');
595
576
  getMpvPlayerModule().loadFile(uri);
596
577
  },