@simba-dev/react-native-media-player 1.4.0 → 1.5.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simba-dev/react-native-media-player",
3
- "version": "1.4.0",
4
- "description": "React Native video/audio player powered by libmpv — Picture-in-Picture, MediaSession, custom RN UI. **V15.0.0 stable release** (2026-09-04) — per-screen simplification + state consolidation. Junior-dev surface across App.tsx AND per-screen code paths. See [`SIMBA_PLAYER_MODULE_V15_FINAL_QA_REPORT.md`](X:/Development/SIMBA/MOBILE_APP_REACT_NATIVE/md/SIMBA_PLAYER_MODULE_V15_FINAL_QA_REPORT.md) for the QA report. Published under the `@simba-dev` org (the bare `simba` org-name on npmjs was reserved at publication time).",
3
+ "version": "1.5.0",
4
+ "description": "React Native video/audio player powered by libmpv — Picture-in-Picture, MediaSession, custom RN UI. **V16.0.0 stable release** (2026-09-07) — API hardening + type-safety sweep. `PlayerQueueItem` is generic; `<SimbaPlayer>` accepts a single `resumePolicy`; the 4 dead-feature stores (sleep/equalizer/liked/shuffle) are removed from the public surface. See `X:/Development/SIMBA/MOBILE_APP_REACT_NATIVE/md/SIMBA_PLAYER_MODULE_V16_*` for the V16 charter, tracker, and final QA report. Published under the `@simba-dev` org (the bare `simba` org-name on npmjs was reserved at publication time).",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
7
7
  "react-native": "src/index.ts",
@@ -3,22 +3,41 @@ import { PlayerProvider } from '../components/PlayerProvider';
3
3
  import type { PlayerConfig } from '../types/config';
4
4
  import { PlayerResumeProvider } from './useOpenWithResume';
5
5
  import type { PlayerResumeLookup } from './useOpenWithResume';
6
- import type { GetResumePosition } from './useSimbaPlayerLookup';
7
6
 
8
7
  /**
9
- * V13+ DX: the single-entry-point wrapper for the SIMBA player
10
- * module. This is the **only** component a consumer's app root
11
- * needs to integrate the module. It composes the three layers a
12
- * typical app needs:
8
+ * V16 Phase 71: a single function the module calls to resolve a saved
9
+ * resume position for a media item. The consumer provides this once
10
+ * at the root of the app; every call site that wants resume-aware
11
+ * openPlayer just passes `resumeId: item.uri` to the hook's returned
12
+ * function.
13
13
  *
14
- * 1. `<PlayerProvider>` — the config + state context (Phase 51).
15
- * 2. `<PlayerResumeProvider>` — the bookmark-aware resume
16
- * lookup used by `useOpenWithResume` (Phase 51/52 + DX).
14
+ * This is the V16 replacement for the V13/V14 4-path API:
15
+ * - V13: `lookup={PlayerResumeLookup}` (object prop)
16
+ * - V14: `getResumePosition={fn}` (function prop)
17
+ * - V14: `useSimbaPlayerLookup(selector)` (factory hook)
18
+ * - V14: `<PlayerResumeProvider lookup={...}>` (manual wrap)
17
19
  *
18
- * Without `<SimbaPlayer>`, the consumer would have to nest both
19
- * providers manually, which is verbose and error-prone for junior
20
- * developers. With `<SimbaPlayer>`, the entire integration is
21
- * **one import + one wrapper component**:
20
+ * V16 collapses all 4 into a single `resumePolicy` function prop on
21
+ * `<SimbaPlayer>`. The internal `PlayerResumeContext` is unchanged.
22
+ *
23
+ * Why the consumer provides the policy (not the module): every
24
+ * project persists bookmarks/history differently - Redux, SQLite,
25
+ * MMKV, AsyncStorage, server-side. The module can't know the
26
+ * shape of the consumer's persistence layer, so the consumer
27
+ * provides a small adapter.
28
+ *
29
+ * The function must be **pure and synchronous**. The module calls
30
+ * it inline at `openPlayer(...)` time. If you need async resolution,
31
+ * hydrate the resume position into the consumer's state first and
32
+ * have the function return the cached value.
33
+ */
34
+ export type ResumePolicy = (itemId: string) => number | undefined;
35
+
36
+ /**
37
+ * V16 Phase 71: the one-import, one-wrapper integration point for
38
+ * `<SimbaPlayer>`. The single `resumePolicy` prop replaces V13's
39
+ * `lookup` object prop, V14's `getResumePosition` function prop,
40
+ * and the V14 `useSimbaPlayerLookup` factory hook.
22
41
  *
23
42
  * @example
24
43
  * ```tsx
@@ -29,7 +48,7 @@ import type { GetResumePosition } from './useSimbaPlayerLookup';
29
48
  * return (
30
49
  * <SimbaPlayer
31
50
  * config={{ theme: { accent: '#FFD700' } }}
32
- * getResumePosition={(uri) =>
51
+ * resumePolicy={(uri) =>
33
52
  * store.getState().bookmarks.byFileUri[uri]?.positionMs
34
53
  * }
35
54
  * >
@@ -39,26 +58,15 @@ import type { GetResumePosition } from './useSimbaPlayerLookup';
39
58
  * }
40
59
  * ```
41
60
  *
42
- * **V14 Phase 61:** the wrapper now accepts EITHER a
43
- * `getResumePosition` function reference (recommended for new
44
- * consumers) OR a `lookup` object (backward-compat for V13-era
45
- * consumers). If both are passed, `getResumePosition` wins.
46
- * The function-prop shape is one function reference instead of
47
- * an object literal — slightly less typing, slightly less
48
- * nesting.
49
- *
50
- * The `lookup` / `getResumePosition` props are optional — pass
51
- * one to enable `useOpenWithResume`'s auto-resume behavior. If
52
- * you only need `usePlayerActivity().openPlayer(...)` (no
53
- * resume lookup), you can omit both and the inner
54
- * `<PlayerResumeProvider>` is still mounted with a no-op lookup
55
- * that always returns `undefined`.
61
+ * The `resumePolicy` prop is optional - omit it and the inner
62
+ * `<PlayerResumeProvider>` is mounted with a no-op policy that
63
+ * always returns `undefined` (resume always falls back to 0 or
64
+ * the consumer-provided `startPositionMs`).
56
65
  *
57
66
  * **Junior-dev rule of thumb:** if your screen calls
58
- * `openPlayer({resumeId: item.id})`, you need a `lookup` or
59
- * `getResumePosition` here. If you only call
60
- * `openPlayer({uri, title, type})` without `resumeId`, the
61
- * lookup is optional.
67
+ * `openPlayer({resumeId: item.id})`, pass a `resumePolicy` here.
68
+ * If you only call `openPlayer({uri, title, type})` without
69
+ * `resumeId`, the policy is optional.
62
70
  */
63
71
  export interface SimbaPlayerProps {
64
72
  /**
@@ -67,35 +75,12 @@ export interface SimbaPlayerProps {
67
75
  */
68
76
  config?: PlayerConfig;
69
77
  /**
70
- * Bookmark-aware resume lookup (object shape). If provided,
71
- * the module's `useOpenWithResume` hook will resolve
72
- * `resumeId` arguments to a `startPositionMs` via this
73
- * object's `getResumePosition` method.
74
- *
75
- * Backward-compat: V13-era consumers that pass a memoized
76
- * `PlayerResumeLookup` object. New consumers should prefer
77
- * the `getResumePosition` function-prop shape.
78
- *
79
- * If both `lookup` and `getResumePosition` are passed,
80
- * `getResumePosition` wins.
81
- */
82
- lookup?: PlayerResumeLookup;
83
- /**
84
- * Bookmark-aware resume lookup (function shape). Receives a
85
- * `resumeId` (typically a URI or item id) and returns the
86
- * saved position in ms, or `undefined` for no saved position.
87
- *
88
- * **Recommended for new consumers.** One function reference
89
- * instead of an object literal:
90
- *
91
- * ```tsx
92
- * <SimbaPlayer getResumePosition={(uri) => store.getState().bookmarks.byFileUri[uri]?.positionMs}>
93
- * ```
94
- *
95
- * If both `lookup` and `getResumePosition` are passed,
96
- * `getResumePosition` wins.
78
+ * V16: bookmark-aware resume lookup, as a single function.
79
+ * Receives a `resumeId` (typically a URI or item id) and
80
+ * returns the saved position in ms, or `undefined` for no
81
+ * saved position.
97
82
  */
98
- getResumePosition?: GetResumePosition;
83
+ resumePolicy?: ResumePolicy;
99
84
  children: React.ReactNode;
100
85
  }
101
86
 
@@ -105,28 +90,25 @@ export interface SimbaPlayerProps {
105
90
  */
106
91
  export function SimbaPlayer({
107
92
  config,
108
- lookup,
109
- getResumePosition,
93
+ resumePolicy,
110
94
  children,
111
95
  }: SimbaPlayerProps): React.ReactElement {
112
- // `getResumePosition` wins over `lookup` if both are passed.
113
- // Memoize the resulting lookup so the `PlayerResumeContext`
114
- // value stays stable across renders — this is what keeps
115
- // every `useOpenWithResume()` consumer from re-rendering on
116
- // every root render.
117
- const effectiveLookup = useMemo<PlayerResumeLookup>(() => {
118
- if (getResumePosition) {
119
- return {getResumePosition};
120
- }
121
- if (lookup) {
122
- return lookup;
96
+ // Wrap the policy in the legacy `PlayerResumeLookup` object
97
+ // shape so the existing `PlayerResumeContext` plumbing is
98
+ // unchanged. Memoize so the `PlayerResumeContext` value
99
+ // stays stable across renders - this is what keeps every
100
+ // `useOpenWithResume()` consumer from re-rendering on every
101
+ // root render.
102
+ const lookup = useMemo<PlayerResumeLookup>(() => {
103
+ if (resumePolicy) {
104
+ return {getResumePosition: resumePolicy};
123
105
  }
124
106
  return noopLookup;
125
- }, [getResumePosition, lookup]);
107
+ }, [resumePolicy]);
126
108
 
127
109
  return (
128
110
  <PlayerProvider config={config}>
129
- <PlayerResumeProvider lookup={effectiveLookup}>
111
+ <PlayerResumeProvider lookup={lookup}>
130
112
  {children}
131
113
  </PlayerResumeProvider>
132
114
  </PlayerProvider>
@@ -134,8 +116,8 @@ export function SimbaPlayer({
134
116
  }
135
117
 
136
118
  /**
137
- * No-op lookup used when the consumer doesn't pass a `lookup`
138
- * or `getResumePosition` prop. Always returns `undefined` so
119
+ * No-op lookup used when the consumer doesn't pass a
120
+ * `resumePolicy`. Always returns `undefined` so
139
121
  * `useOpenWithResume` falls back to 0 (or the
140
122
  * consumer-provided `startPositionMs`).
141
123
  */
@@ -9,12 +9,14 @@ import type {
9
9
  } from '../stores/playerQueueStore';
10
10
 
11
11
  /**
12
- * V15 Phase 65: the public hook for queue + playback-history state.
12
+ * V15 Phase 65 (V16 Phase 69 hardened): the public hook for queue +
13
+ * playback-history state.
13
14
  *
14
- * Returns the full store: `{queue, playbackHistory, addToQueue, ...}`.
15
- * Use with a selector (and `useShallow` for object selectors) to
16
- * subscribe to a slice of the state and avoid unnecessary
17
- * re-renders.
15
+ * Two overloads:
16
+ * - `useQueue()` returns the full store `{queue, playbackHistory, addToQueue, ...}`.
17
+ * - `useQueue(selector)` returns the selected slice (use `useShallow`
18
+ * on object selectors to subscribe by-value and avoid unnecessary
19
+ * re-renders).
18
20
  *
19
21
  * @example
20
22
  * ```tsx
@@ -30,13 +32,15 @@ import type {
30
32
  * }
31
33
  * ```
32
34
  */
33
- export function useQueue<T = PlayerQueueStore>(
35
+ export function useQueue(): PlayerQueueStore;
36
+ export function useQueue<T>(selector: (state: PlayerQueueStore) => T): T;
37
+ export function useQueue<T>(
34
38
  selector?: (state: PlayerQueueStore) => T,
35
- ): T {
39
+ ): PlayerQueueStore | T {
36
40
  if (selector) {
37
41
  return useStore(usePlayerQueueStore, useShallow(selector));
38
42
  }
39
- return useStore(usePlayerQueueStore) as unknown as T;
43
+ return useStore(usePlayerQueueStore);
40
44
  }
41
45
 
42
46
  /** Convenience hook: just the queue length. */
@@ -49,9 +53,40 @@ export function useQueueItems(): PlayerQueueItem[] {
49
53
  return useStore(usePlayerQueueStore, state => state.queue);
50
54
  }
51
55
 
56
+ /**
57
+ * V16 Phase 70: typed convenience hook for the queue array.
58
+ *
59
+ * Returns `useQueueItems()` cast to `T[]`. Use this when the
60
+ * consumer wants to specialize `PlayerQueueItem` to its own
61
+ * narrow literal unions (e.g.
62
+ * `PlayerQueueItem<MediaSource, MediaKind, MediaLane>`) so the
63
+ * items round-trip through `addToQueue` / `useQueueItemsAs`
64
+ * without `as unknown as` casts at the boundary.
65
+ *
66
+ * The runtime contract: the module's queue store accepts any
67
+ * `PlayerQueueItem` shape on write, so an item added with
68
+ * `PlayerQueueItem<MediaSource, MediaKind, MediaLane>` is
69
+ * stored structurally. The cast on read asserts the consumer's
70
+ * domain knowledge that the items in the queue are typed.
71
+ *
72
+ * The cast lives here (one place) instead of being scattered
73
+ * across every read site in the consumer.
74
+ */
75
+ export function useQueueItemsAs<T extends PlayerQueueItem = PlayerQueueItem>(): T[] {
76
+ return useStore(usePlayerQueueStore, state => state.queue as T[]);
77
+ }
78
+
52
79
  /** Convenience hook: just the playback history array. */
53
80
  export function usePlaybackHistory(): PlayerQueueItem[] {
54
81
  return useStore(usePlayerQueueStore, state => state.playbackHistory);
55
82
  }
56
83
 
84
+ /**
85
+ * V16 Phase 70: typed convenience hook for the playback history.
86
+ * See {@link useQueueItemsAs} for the cast contract.
87
+ */
88
+ export function usePlaybackHistoryAs<T extends PlayerQueueItem = PlayerQueueItem>(): T[] {
89
+ return useStore(usePlayerQueueStore, state => state.playbackHistory as T[]);
90
+ }
91
+
57
92
  export type {PlayerQueueItem, PlayerQueueStore} from '../stores/playerQueueStore';
@@ -3,9 +3,13 @@ import {usePlayerQueueSelectionStore} from '../stores/playerQueueSelectionStore'
3
3
  import type {PlayerQueueSelectionStore} from '../stores/playerQueueSelectionStore';
4
4
 
5
5
  /**
6
- * V15 Phase 65: the public hook for queue multi-select state.
6
+ * V15 Phase 65 (V16 Phase 69 hardened): the public hook for queue
7
+ * multi-select state.
7
8
  *
8
- * Returns the full selection store: `{selectedIndices, setSelection, clearSelection, removeSelected, moveSelectedToTop}`.
9
+ * Two overloads:
10
+ * - `useQueueSelection()` returns the full store
11
+ * `{selectedIndices, setSelection, clearSelection, removeSelected, moveSelectedToTop}`.
12
+ * - `useQueueSelection(selector)` returns the selected slice.
9
13
  *
10
14
  * @example
11
15
  * ```tsx
@@ -15,13 +19,17 @@ import type {PlayerQueueSelectionStore} from '../stores/playerQueueSelectionStor
15
19
  * }
16
20
  * ```
17
21
  */
18
- export function useQueueSelection<T = PlayerQueueSelectionStore>(
22
+ export function useQueueSelection(): PlayerQueueSelectionStore;
23
+ export function useQueueSelection<T>(
24
+ selector: (state: PlayerQueueSelectionStore) => T,
25
+ ): T;
26
+ export function useQueueSelection<T>(
19
27
  selector?: (state: PlayerQueueSelectionStore) => T,
20
- ): T {
28
+ ): PlayerQueueSelectionStore | T {
21
29
  if (selector) {
22
30
  return useStore(usePlayerQueueSelectionStore, selector);
23
31
  }
24
- return useStore(usePlayerQueueSelectionStore) as unknown as T;
32
+ return useStore(usePlayerQueueSelectionStore);
25
33
  }
26
34
 
27
35
  /** Convenience hook: just the selected indices. */
package/src/index.ts CHANGED
@@ -74,11 +74,7 @@ export {
74
74
  type PlayerResumeProviderProps,
75
75
  } from './hooks/useOpenWithResume';
76
76
 
77
- export {SimbaPlayer, type SimbaPlayerProps} from './hooks/SimbaPlayer';
78
- export {
79
- useSimbaPlayerLookup,
80
- type GetResumePosition,
81
- } from './hooks/useSimbaPlayerLookup';
77
+ export {SimbaPlayer, type SimbaPlayerProps, type ResumePolicy} from './hooks/SimbaPlayer';
82
78
  export {SimbaPlayerRoot, type SimbaPlayerRootProps} from './hooks/SimbaPlayerRoot';
83
79
  export {useOpenFromUrl} from './hooks/useOpenFromUrl';
84
80
  export {
@@ -91,7 +87,9 @@ export {
91
87
  useQueue,
92
88
  useQueueLength,
93
89
  useQueueItems,
90
+ useQueueItemsAs,
94
91
  usePlaybackHistory,
92
+ usePlaybackHistoryAs,
95
93
  type PlayerQueueItem,
96
94
  type PlayerQueueStore,
97
95
  } from './hooks/useQueue';
@@ -100,22 +98,6 @@ export {
100
98
  useQueueSelectedIndices,
101
99
  type PlayerQueueSelectionStore,
102
100
  } from './hooks/useQueueSelection';
103
- export {
104
- useSleepTimer,
105
- useSleepTimerEnd,
106
- useSleepTimerMode,
107
- useEqualizer,
108
- useEqualizerEnabled,
109
- useIsLiked,
110
- useToggleLiked,
111
- useShuffle,
112
- useShuffleEnabled,
113
- type PlayerSleepTimerStore,
114
- type SleepTimerMode,
115
- type PlayerEqualizerStore,
116
- type PlayerLikedStore,
117
- type PlayerShuffleStore,
118
- } from './hooks/usePlayerFeatureHooks';
119
101
  export {useLaunchParams} from './hooks/useLaunchParams';
120
102
 
121
103
  export {
@@ -1,7 +1,7 @@
1
1
  import {create} from 'zustand';
2
2
 
3
3
  /**
4
- * V15 Phase 65: the queue item shape exposed by `useQueue()`.
4
+ * V16 Phase 69: the queue item shape exposed by `useQueue()`.
5
5
  *
6
6
  * Structurally a superset of the consumer's V14 `playerSlice`
7
7
  * queue entry. `uri` and `title` are required; the rest are
@@ -9,27 +9,52 @@ import {create} from 'zustand';
9
9
  * inspect these fields — they're retained so the UI can
10
10
  * display rich row content.
11
11
  *
12
- * `type` and `mediaType` are typed as `string` (not the narrower
13
- * `'audio' | 'video'`) so consumers with richer content kinds
14
- * (e.g. `'music' | 'movie' | 'podcast'`) can pass items without
15
- * TypeScript rejecting the object. The module doesn't read
16
- * these fields; the consumer's UI does.
12
+ * The three classification fields (`source`, `type`, `mediaType`)
13
+ * are **generic** with `string` defaults. Consumers with
14
+ * narrower literal unions (e.g. `MediaSource`/`MediaKind`/
15
+ * `MediaLane` for SIMBA) specialize the generic:
16
+ *
17
+ * ```ts
18
+ * interface MyEntry extends PlayerQueueItem<MediaSource, MediaKind, MediaLane> {
19
+ * // consumer-only fields
20
+ * }
21
+ * ```
22
+ *
23
+ * With the generic specialized, a `MyEntry` flows through
24
+ * `addToQueue(entry)` and back via `useQueueItems()` without
25
+ * the consumer needing `as unknown as` casts at the boundary.
26
+ *
27
+ * Default usage (`PlayerQueueItem` with no generics) is
28
+ * backward-compatible with V15 — the three fields stay `string`.
29
+ *
30
+ * `resumePosition` and `autoplay` are added in V16 so a
31
+ * consumer's `PlaybackEntry` can extend `PlayerQueueItem`
32
+ * directly without losing its existing fields.
17
33
  */
18
- export interface PlayerQueueItem {
34
+ export interface PlayerQueueItem<
35
+ TSource extends string = string,
36
+ TKind extends string = string,
37
+ TLane extends string = string,
38
+ > {
19
39
  uri: string;
20
40
  title: string;
21
41
  duration: number;
22
42
  artist?: string;
23
43
  album?: string;
24
44
  artworkUri?: string;
25
- /** Wide string for consumer flexibility (e.g. `MediaSource`). */
26
- source?: string;
27
- /** Stream type or content kind. Wide string for consumer flexibility. */
28
- type?: string;
29
- mediaType?: string;
45
+ /** Coarse provenance (e.g. `MediaSource` = 'local' | 'api'). */
46
+ source?: TSource;
47
+ /** Stream type or content kind (e.g. `MediaKind`). */
48
+ type?: TKind;
49
+ /** Playback lane (e.g. `MediaLane` = 'audio' | 'video'). */
50
+ mediaType?: TLane;
30
51
  provider?: string;
31
52
  /** Stable linked-folder identity for local entries. */
32
53
  folderId?: string;
54
+ /** V16: last native-confirmed playback position for resume. */
55
+ resumePosition?: number;
56
+ /** V16: whether the item should auto-play on load. */
57
+ autoplay?: boolean;
33
58
  }
34
59
 
35
60
  /**
@@ -61,14 +86,15 @@ export interface PlayerQueueActions {
61
86
  */
62
87
  shuffleQueue: () => void;
63
88
  /**
64
- * Promote a queue item to the module's playlist and play it.
65
- *
66
- * The queue stays display-only for the rest of the playback
67
- * (the module's `next()` doesn't consume it). Phase 65 keeps
68
- * the same semantics as the V14 `playFromQueue` reducer in
69
- * `playerSlice`.
89
+ * V16 Phase 72: rename from `playFromQueue`. The old name
90
+ * implied "play this item" but the implementation only
91
+ * removed the item from the queue - it never promoted the
92
+ * item to the active playlist. The new name is honest about
93
+ * what the action does. To actually promote a queue item to
94
+ * the active playlist and play it, the consumer should call
95
+ * `useOpenPlaylist()` separately.
70
96
  */
71
- playFromQueue: (index: number) => void;
97
+ removeFromQueueByIndex: (index: number) => void;
72
98
 
73
99
  /** Append a single item to the playback history. */
74
100
  addToPlaybackHistory: (item: PlayerQueueItem) => void;
@@ -85,16 +111,14 @@ export interface PlayerQueueStore extends PlayerQueueActions {
85
111
  }
86
112
 
87
113
  /**
88
- * V15 Phase 65: a no-op placeholder for `playFromQueue` that
89
- * the module-side store doesn't directly drive. The actual
90
- * playlist update is performed by the activity via
91
- * `bridge.loadPlaylist` + `bridge.setTrack`; for now, the
92
- * store just removes the item from the queue (Phase 65 is
93
- * the data-consolidation step; the actual playlist command
94
- * remains consumer's responsibility until Phase 66 or a
95
- * follow-up phase consolidates it too).
114
+ * V16 Phase 72: rename from `playFromQueueImpl`. The old name
115
+ * implied "promote to playlist + play" but the implementation
116
+ * only spliced the item from the queue. The new name reflects
117
+ * what the action actually does: remove from queue. To
118
+ * promote a queue item to the active playlist, the consumer
119
+ * should call `useOpenPlaylist()` separately.
96
120
  */
97
- function playFromQueueImpl(
121
+ function removeFromQueueByIndexImpl(
98
122
  set: (updater: (state: PlayerQueueStore) => PlayerQueueStore) => void,
99
123
  index: number,
100
124
  ): void {
@@ -154,7 +178,7 @@ export const usePlayerQueueStore = create<PlayerQueueStore>()((set) => ({
154
178
  }
155
179
  return {queue: q};
156
180
  }),
157
- playFromQueue: (index) => playFromQueueImpl(set, index),
181
+ removeFromQueueByIndex: (index) => removeFromQueueByIndexImpl(set, index),
158
182
 
159
183
  addToPlaybackHistory: (item) =>
160
184
  set(state => ({playbackHistory: [...state.playbackHistory, item]})),
@@ -1,94 +0,0 @@
1
- import {useStore} from 'zustand';
2
- import {
3
- usePlayerSleepTimerStore,
4
- type PlayerSleepTimerStore,
5
- type SleepTimerMode,
6
- } from '../stores/playerSleepTimerStore';
7
- import {
8
- usePlayerEqualizerStore,
9
- type PlayerEqualizerStore,
10
- } from '../stores/playerEqualizerStore';
11
- import {
12
- usePlayerLikedStore,
13
- type PlayerLikedStore,
14
- } from '../stores/playerLikedStore';
15
- import {
16
- usePlayerShuffleStore,
17
- type PlayerShuffleStore,
18
- } from '../stores/playerShuffleStore';
19
-
20
- /**
21
- * V15 Phase 66: the sleep-timer hook.
22
- *
23
- * @example
24
- * ```tsx
25
- * const {endTime, setTimer, clear} = useSleepTimer();
26
- * const handle30Min = () => setTimer(30 * 60);
27
- * ```
28
- */
29
- export function useSleepTimer(): PlayerSleepTimerStore {
30
- return useStore(usePlayerSleepTimerStore);
31
- }
32
-
33
- /** Convenience hook: just the end time (or null). */
34
- export function useSleepTimerEnd(): number | null {
35
- return useStore(usePlayerSleepTimerStore, state => state.endTime);
36
- }
37
-
38
- /** Convenience hook: just the mode. */
39
- export function useSleepTimerMode(): SleepTimerMode {
40
- return useStore(usePlayerSleepTimerStore, state => state.mode);
41
- }
42
-
43
- /**
44
- * V15 Phase 66: the equalizer hook.
45
- *
46
- * @example
47
- * ```tsx
48
- * const {gains, enabled, setGains, toggle} = useEqualizer();
49
- * ```
50
- */
51
- export function useEqualizer(): PlayerEqualizerStore {
52
- return useStore(usePlayerEqualizerStore);
53
- }
54
-
55
- /** Convenience hook: just the enabled flag. */
56
- export function useEqualizerEnabled(): boolean {
57
- return useStore(usePlayerEqualizerStore, state => state.enabled);
58
- }
59
-
60
- /**
61
- * V15 Phase 66: the per-file "liked" hook.
62
- *
63
- * @example
64
- * ```tsx
65
- * const isLiked = useIsLiked(uri);
66
- * const toggle = useToggleLiked();
67
- * <Pressable onPress={() => toggle(uri)}>{isLiked ? '♥' : '♡'}</Pressable>
68
- * ```
69
- */
70
- export function useIsLiked(uri: string): boolean {
71
- return useStore(usePlayerLikedStore, state => !!state.liked[uri]);
72
- }
73
-
74
- export function useToggleLiked(): (uri: string) => boolean {
75
- return useStore(usePlayerLikedStore, state => state.toggle);
76
- }
77
-
78
- /** V15 Phase 66: the shuffle hook. */
79
- export function useShuffle(): PlayerShuffleStore {
80
- return useStore(usePlayerShuffleStore);
81
- }
82
-
83
- /** Convenience hook: just the shuffle enabled flag. */
84
- export function useShuffleEnabled(): boolean {
85
- return useStore(usePlayerShuffleStore, state => state.enabled);
86
- }
87
-
88
- export type {
89
- PlayerSleepTimerStore,
90
- SleepTimerMode,
91
- } from '../stores/playerSleepTimerStore';
92
- export type {PlayerEqualizerStore} from '../stores/playerEqualizerStore';
93
- export type {PlayerLikedStore} from '../stores/playerLikedStore';
94
- export type {PlayerShuffleStore} from '../stores/playerShuffleStore';
@@ -1,58 +0,0 @@
1
- import {useMemo} from 'react';
2
- import type {PlayerResumeLookup} from './useOpenWithResume';
3
-
4
- /**
5
- * V14 Phase 61: a function the module calls to resolve a saved
6
- * resume position for a media item. The consumer provides this
7
- * once at the root of the app; every call site that wants
8
- * resume-aware openPlayer just passes `resumeId: item.uri` to
9
- * the hook's returned function.
10
- *
11
- * Mirrors the body of `PlayerResumeLookup.getResumePosition` —
12
- * kept as a named type so `<SimbaPlayer getResumePosition={...}>`
13
- * has a self-documenting prop type instead of an inline arrow.
14
- */
15
- export type GetResumePosition = (itemId: string) => number | undefined;
16
-
17
- const noopLookup: PlayerResumeLookup = {
18
- getResumePosition: () => undefined,
19
- };
20
-
21
- /**
22
- * V14 Phase 61: factory hook for a stable `PlayerResumeLookup`.
23
- *
24
- * Wraps an optional `selector` function in a memoized
25
- * `PlayerResumeLookup` object so the lookup reference stays
26
- * stable across renders. The point of this hook is to ship the
27
- * **shape** so the consumer's `lookup={}` is always type-safe
28
- * + stable — the consumer never has to write `useMemo<PlayerResumeLookup>(...)`
29
- * themselves.
30
- *
31
- * Without a selector, returns a no-op lookup (always returns
32
- * `undefined`).
33
- *
34
- * @example
35
- * ```tsx
36
- * // With a selector (most common):
37
- * const resumeLookup = useSimbaPlayerLookup((uri) =>
38
- * store.getState().bookmarks.byFileUri[uri]?.positionMs,
39
- * );
40
- *
41
- * return (
42
- * <SimbaPlayer lookup={resumeLookup}>
43
- * <AppContent />
44
- * </SimbaPlayer>
45
- * );
46
- *
47
- * // Or — the function-prop shape (recommended for new consumers):
48
- * <SimbaPlayer getResumePosition={(uri) => store.getState().bookmarks.byFileUri[uri]?.positionMs} />
49
- * ```
50
- */
51
- export function useSimbaPlayerLookup(
52
- selector?: GetResumePosition,
53
- ): PlayerResumeLookup {
54
- return useMemo<PlayerResumeLookup>(() => {
55
- if (!selector) return noopLookup;
56
- return {getResumePosition: selector};
57
- }, [selector]);
58
- }
@@ -1,34 +0,0 @@
1
- import {create} from 'zustand';
2
-
3
- /**
4
- * V15 Phase 66: a 10-band equalizer state.
5
- *
6
- * `gains` is a fixed-length array of 10 numeric gains (one
7
- * per band, in dB). `enabled` toggles whether the equalizer
8
- * is active. The module's mpv-backed equalizer is the
9
- * authoritative sink for these values; the store is a UI
10
- * surface.
11
- */
12
- export type EqualizerGains = [number, number, number, number, number, number, number, number, number, number];
13
-
14
- export interface PlayerEqualizerStore {
15
- gains: EqualizerGains;
16
- enabled: boolean;
17
- /** Replace the gains array. Must be length 10; otherwise no-op. */
18
- setGains: (gains: number[]) => void;
19
- /** Toggle the equalizer on/off. */
20
- toggle: () => void;
21
- }
22
-
23
- const DEFAULT_GAINS: EqualizerGains = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
24
-
25
- export const usePlayerEqualizerStore = create<PlayerEqualizerStore>()((set) => ({
26
- gains: DEFAULT_GAINS,
27
- enabled: false,
28
-
29
- setGains: (incoming) => {
30
- if (incoming.length !== 10) return;
31
- set({gains: incoming as EqualizerGains});
32
- },
33
- toggle: () => set(state => ({enabled: !state.enabled})),
34
- }));
@@ -1,39 +0,0 @@
1
- import {create} from 'zustand';
2
-
3
- /**
4
- * V15 Phase 66: the "liked" per-file state.
5
- *
6
- * Stored as `Record<fileUri, boolean>`. The UI surface for
7
- * the "♥" / "♡" toggle on each track. Persisted via
8
- * `zustand/middleware/persist` (AsyncStorage) — the only
9
- * player-related state the consumer needs across remounts
10
- * and devices.
11
- *
12
- * The store lives in the module so the player integration
13
- * can read the like flag without depending on Redux or
14
- * redux-persist.
15
- */
16
- export interface PlayerLikedStore {
17
- liked: Record<string, boolean>;
18
- /** Returns whether the given URI is liked. */
19
- isLiked: (uri: string) => boolean;
20
- /**
21
- * Toggle the like flag for a single URI. Idempotent.
22
- * Returns the new boolean value.
23
- */
24
- toggle: (uri: string) => boolean;
25
- }
26
-
27
- export const usePlayerLikedStore = create<PlayerLikedStore>()((set, get) => ({
28
- liked: {},
29
-
30
- isLiked: (uri) => !!get().liked[uri],
31
-
32
- toggle: (uri) => {
33
- if (!uri) return false;
34
- const current = !!get().liked[uri];
35
- const next = !current;
36
- set(state => ({liked: {...state.liked, [uri]: next}}));
37
- return next;
38
- },
39
- }));
@@ -1,18 +0,0 @@
1
- import {create} from 'zustand';
2
-
3
- /**
4
- * V15 Phase 66: the shuffle flag.
5
- *
6
- * A boolean. The V14-era consumer-side redux `state.player.shuffle`
7
- * is gone; consumers now read this flag via `useShuffle()` and
8
- * toggle it via `useShuffle().toggle()`.
9
- */
10
- export interface PlayerShuffleStore {
11
- enabled: boolean;
12
- toggle: () => void;
13
- }
14
-
15
- export const usePlayerShuffleStore = create<PlayerShuffleStore>()((set) => ({
16
- enabled: false,
17
- toggle: () => set(state => ({enabled: !state.enabled})),
18
- }));
@@ -1,45 +0,0 @@
1
- import {create} from 'zustand';
2
-
3
- /**
4
- * V15 Phase 66: the sleep-timer state.
5
- *
6
- * `endTime` is a Unix timestamp in ms; the UI can compare it
7
- * to `Date.now()` to render a countdown. `null` means the
8
- * timer is disarmed.
9
- *
10
- * `mode` selects the expiry trigger:
11
- * - `'time'`: countdown fires at `endTime`
12
- * - `'track'`: fires at the next track boundary
13
- * - `'chapter'`: fires at the next chapter boundary
14
- */
15
- export type SleepTimerMode = 'time' | 'track' | 'chapter';
16
-
17
- export interface PlayerSleepTimerStore {
18
- endTime: number | null;
19
- mode: SleepTimerMode;
20
- /**
21
- * Arm a countdown timer that fires after `seconds` from now.
22
- * Always sets `mode` to 'time'. Pass `null` to disarm.
23
- */
24
- setTimer: (seconds: number | null) => void;
25
- /**
26
- * Set the trigger mode. Mode-based expiry replaces any
27
- * countdown timer (clears `endTime`).
28
- */
29
- setMode: (mode: SleepTimerMode) => void;
30
- /** Disarm the timer. */
31
- clear: () => void;
32
- }
33
-
34
- export const usePlayerSleepTimerStore = create<PlayerSleepTimerStore>()((set) => ({
35
- endTime: null,
36
- mode: 'time',
37
-
38
- setTimer: (seconds) =>
39
- set(() => ({
40
- endTime: seconds !== null ? Date.now() + seconds * 1000 : null,
41
- mode: 'time',
42
- })),
43
- setMode: (mode) => set({mode, endTime: null}),
44
- clear: () => set({endTime: null}),
45
- }));