@simba-dev/react-native-media-player 1.2.0 → 1.4.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.
@@ -0,0 +1,174 @@
1
+ import {useCallback} from 'react';
2
+ import {useOpenWithResume} from './useOpenWithResume';
3
+
4
+ /**
5
+ * V14 Phase 60: the deep-link helper hook.
6
+ *
7
+ * Apps that handle "open with" / Android Share Sheet / cold-start
8
+ * deep links all converge on the same boilerplate:
9
+ *
10
+ * 1. Listen for `Linking.addEventListener('url', ...)`.
11
+ * 2. On cold start, also call `Linking.getInitialURL()`.
12
+ * 3. Filter for the URI schemes the app handles (typically
13
+ * `content://` and `file://` for shared media files).
14
+ * 4. Derive a display title from the URI basename.
15
+ * 5. Classify the file as audio or video (typically by extension).
16
+ * 6. Forward to the player via `openPlayer({uri, title, type, ...})`.
17
+ *
18
+ * Before V14, every consumer wrote this glue themselves. The shape
19
+ * was always the same; only the title-derivation heuristic and
20
+ * the extension lists varied.
21
+ *
22
+ * `useOpenFromUrl` absorbs steps 3–6. The consumer still owns step
23
+ * 1 + 2 (the `Linking` plumbing), but those are 4 lines of React
24
+ * boilerplate that any RN dev can write. The type-classification
25
+ * + title-derivation + openPlayer forwarding is the actual glue.
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * const openFromUrl = useOpenFromUrl();
30
+ *
31
+ * useEffect(() => {
32
+ * Linking.getInitialURL().then(url => url && openFromUrl(url));
33
+ * const sub = Linking.addEventListener('url', ({url}) => openFromUrl(url));
34
+ * return () => sub.remove();
35
+ * }, [openFromUrl]);
36
+ * ```
37
+ */
38
+
39
+ /**
40
+ * Audio file extensions (lowercase, no dot). Conservative list —
41
+ * any consumer with a custom format can pass a `classifyType` prop
42
+ * (TODO if needed; not in V14 spec).
43
+ */
44
+ const AUDIO_EXTENSIONS = new Set([
45
+ 'mp3',
46
+ 'm4a',
47
+ 'm4b',
48
+ 'aac',
49
+ 'flac',
50
+ 'ogg',
51
+ 'opus',
52
+ 'wav',
53
+ 'wma',
54
+ 'aiff',
55
+ 'alac',
56
+ 'mp2',
57
+ 'amr',
58
+ 'ac3',
59
+ 'oga',
60
+ ]);
61
+
62
+ /**
63
+ * Video file extensions (lowercase, no dot). Same conservatism
64
+ * as `AUDIO_EXTENSIONS`.
65
+ */
66
+ const VIDEO_EXTENSIONS = new Set([
67
+ 'mp4',
68
+ 'm4v',
69
+ 'mkv',
70
+ 'webm',
71
+ 'avi',
72
+ 'mov',
73
+ 'wmv',
74
+ 'flv',
75
+ 'ts',
76
+ 'm2ts',
77
+ 'mpg',
78
+ 'mpeg',
79
+ 'vob',
80
+ 'ogv',
81
+ '3gp',
82
+ '3g2',
83
+ 'f4v',
84
+ 'mp2p',
85
+ ]);
86
+
87
+ /**
88
+ * Pull the extension off a URI basename. Strips any query string
89
+ * or fragment first (so `foo.MP3?token=abc` returns `mp3`). Returns
90
+ * an empty string if the basename has no extension.
91
+ */
92
+ function getExtension(uri: string): string {
93
+ const clean = uri.split('?')[0].split('#')[0];
94
+ // Take the last path segment. Use both / and \\ separators so
95
+ // file:// URIs from Windows-style paths still work.
96
+ const basename = clean.split(/[/\\]/).pop() || '';
97
+ const dot = basename.lastIndexOf('.');
98
+ return dot >= 0 ? basename.slice(dot + 1).toLowerCase() : '';
99
+ }
100
+
101
+ /**
102
+ * Classify a media URI as 'audio' or 'video' by file extension.
103
+ * Unknown extensions default to 'video' — matches the SIMBA
104
+ * consumer's pre-V14 convention. (The video default is permissive:
105
+ * if we guess wrong, the player handles both via mpv. Defaulting
106
+ * to audio would silently hide the surface for a video file.)
107
+ */
108
+ function classifyMediaType(uri: string): 'audio' | 'video' {
109
+ const ext = getExtension(uri);
110
+ if (VIDEO_EXTENSIONS.has(ext)) return 'video';
111
+ if (AUDIO_EXTENSIONS.has(ext)) return 'audio';
112
+ return 'video';
113
+ }
114
+
115
+ /**
116
+ * Derive a human-readable display name from a URI. Strips the
117
+ * file extension, URL-decodes the basename, and falls back to
118
+ * 'Shared File' if the URI has no usable path component.
119
+ */
120
+ function deriveDisplayName(uri: string): string {
121
+ const clean = uri.split('?')[0].split('#')[0];
122
+ const fileName = clean.split('/').pop() || 'Shared File';
123
+ const noExt = fileName.replace(/\.[^.]+$/, '');
124
+ try {
125
+ return decodeURIComponent(noExt) || 'Shared File';
126
+ } catch {
127
+ // Malformed URI — fall back to the raw basename.
128
+ return noExt || 'Shared File';
129
+ }
130
+ }
131
+
132
+ /**
133
+ * V14 Phase 60: the deep-link helper hook.
134
+ *
135
+ * Returns a stable callback that takes a URI string and, if the
136
+ * URI looks like a sharable media file (`content://` or `file://`),
137
+ * opens it in the player with a derived title + classified type.
138
+ * Returns `false` for URIs the hook ignores (empty / wrong scheme).
139
+ *
140
+ * The returned callback composes with the nearest
141
+ * `<PlayerResumeProvider>` (set up by `<SimbaPlayer>` in the
142
+ * consumer's App root): the URI is passed as `resumeId` so the
143
+ * consumer's bookmark lookup runs. If the URI has a saved
144
+ * bookmark, playback resumes from that position; otherwise the
145
+ * file plays from the start.
146
+ */
147
+ export function useOpenFromUrl(): (uri: string) => Promise<boolean> {
148
+ const openPlayer = useOpenWithResume();
149
+ return useCallback(
150
+ async (uri: string): Promise<boolean> => {
151
+ // Defensive: empty / non-sharable URIs are no-ops.
152
+ if (!uri) return false;
153
+ if (!uri.startsWith('content://') && !uri.startsWith('file://')) {
154
+ return false;
155
+ }
156
+
157
+ const title = deriveDisplayName(uri);
158
+ const type = classifyMediaType(uri);
159
+
160
+ // Pass the URI as `resumeId` so the consumer's bookmark
161
+ // lookup runs. Shared content:// URIs are not in the
162
+ // bookmark slice, so the lookup typically returns 0 (start
163
+ // from the beginning). But if the user previously saved a
164
+ // bookmark for the same URI, playback resumes from there.
165
+ return openPlayer({
166
+ uri,
167
+ title,
168
+ type,
169
+ resumeId: uri,
170
+ });
171
+ },
172
+ [openPlayer],
173
+ );
174
+ }
@@ -0,0 +1,188 @@
1
+ import {useCallback} from 'react';
2
+ import {usePlayerActivity} from './usePlayerActivity';
3
+ import type {OpenPlayerOptions} from './usePlayerActivity';
4
+
5
+ /**
6
+ * V15 Phase 64: a minimal entry shape for `useOpenPlaylist`.
7
+ *
8
+ * Structurally — any object with at least `uri` and `title` qualifies.
9
+ * The consumer's full `PlaylistEntry` (which has `duration`, `source`,
10
+ * `type`, `mediaType`, `provider`, `folderId`) matches this without
11
+ * any explicit cast. The hook only reads `uri` and `title`; the
12
+ * rest of the entry is ignored.
13
+ */
14
+ export interface PlayableEntry {
15
+ uri: string;
16
+ title: string;
17
+ }
18
+
19
+ /**
20
+ * V15 Phase 64: options for `openPlaylist`.
21
+ */
22
+ export interface OpenPlaylistOptions {
23
+ /** Stream type for the start track. Defaults to 'audio'. */
24
+ type?: 'video' | 'audio';
25
+ /**
26
+ * Index into `entries` of the track to start playback from.
27
+ * Defaults to 0 (the first track). If `shuffle: true` and
28
+ * `startIndex` is not provided, a random non-zero index is
29
+ * chosen (so shuffle doesn't start from index 0 by convention;
30
+ * but pass 0 explicitly if you want that).
31
+ */
32
+ startIndex?: number;
33
+ /**
34
+ * Optional start position in ms for the start track. Useful
35
+ * when the consumer has a saved bookmark for the first
36
+ * track and wants playback to resume from that position.
37
+ * (For per-track resume, the consumer should pre-dispatch
38
+ * a seek after the activity launches; the lookup configured
39
+ * via `<SimbaPlayer>` is not applied here — `useOpenPlaylist`
40
+ * calls `usePlayerActivity().openPlayer`, not the
41
+ * `useOpenWithResume` variant.)
42
+ */
43
+ startPositionMs?: number;
44
+ /**
45
+ * If true, Fisher-Yates shuffles a copy of `entries` before
46
+ * picking the start track. The original `entries` array is
47
+ * not mutated. The shuffle is in-place on the copy.
48
+ */
49
+ shuffle?: boolean;
50
+ /**
51
+ * Extra fields forwarded to the start track's `openPlayer`
52
+ * call. Useful for consumer-specific metadata like
53
+ * `provider`, `folderId`, `artworkUri`, `subtitleUri`, etc.
54
+ *
55
+ * These override any defaults the hook sets (e.g. `type`).
56
+ * If you pass `type` in `startExtras`, it wins over the
57
+ * `type` option.
58
+ *
59
+ * Typed loosely (`Record<string, unknown>`) so consumers
60
+ * can spread conditional fields without TypeScript's excess
61
+ * property check rejecting the whole object. The fields
62
+ * are forwarded verbatim to `openPlayer({...})`; unknown
63
+ * fields are dropped by the consumer's call site (or
64
+ * accepted if the consumer wraps the call).
65
+ */
66
+ startExtras?: Record<string, unknown>;
67
+ }
68
+
69
+ /**
70
+ * V15 Phase 64: the return value of `useOpenPlaylist`.
71
+ */
72
+ export interface UseOpenPlaylistResult {
73
+ /**
74
+ * Open the given list of entries in the player. The first
75
+ * track (or the track at `startIndex`) is the activity's
76
+ * launch payload. Returns `false` if `entries` is empty.
77
+ *
78
+ * This is the "play all from a list" pattern. The hook
79
+ * absorbs the start-track extraction, optional shuffle,
80
+ * and `openPlayer` call. The consumer does NOT need to
81
+ * dispatch `loadPlaylistToPlayer` separately — that's a
82
+ * consumer-side concern (see V15 Phase 65 for the state
83
+ * consolidation that absorbs that too).
84
+ *
85
+ * @example
86
+ * ```tsx
87
+ * const {openPlaylist} = useOpenPlaylist();
88
+ *
89
+ * const handlePlayAll = () => openPlaylist(sortedTracks, {type: 'audio'});
90
+ * const handleShuffle = () => openPlaylist(sortedTracks, {type: 'audio', shuffle: true});
91
+ * const handlePlayFromThird = () => openPlaylist(sortedTracks, {type: 'audio', startIndex: 2});
92
+ * ```
93
+ */
94
+ openPlaylist(
95
+ entries: PlayableEntry[],
96
+ opts?: OpenPlaylistOptions,
97
+ ): Promise<boolean>;
98
+ }
99
+
100
+ /**
101
+ * V15 Phase 64: factory hook for the "play all" pattern.
102
+ *
103
+ * Replaces the 12-30 line two-step pattern every consumer
104
+ * wrote:
105
+ *
106
+ * ```tsx
107
+ * // Before (V14)
108
+ * const handlePlayAll = useCallback(() => {
109
+ * const entries = sortedTracks.map(t => ({...t}));
110
+ * if (entries.length === 0) return;
111
+ * dispatch(loadPlaylistToPlayer(entries)); // consumer-side
112
+ * openPlayer({
113
+ * uri: entries[0].uri,
114
+ * title: entries[0].title,
115
+ * type: 'audio',
116
+ * });
117
+ * }, [sortedTracks, dispatch, openPlayer]);
118
+ *
119
+ * // After (V15 Phase 64)
120
+ * const {openPlaylist} = useOpenPlaylist();
121
+ * const handlePlayAll = useCallback(() => {
122
+ * openPlaylist(sortedTracks, {type: 'audio'});
123
+ * }, [openPlaylist, sortedTracks]);
124
+ * ```
125
+ *
126
+ * **Phase 64 scope**: the hook calls `openPlayer` with the
127
+ * first track. The consumer's `loadPlaylistToPlayer` dispatch
128
+ * is still required if the consumer's Queue UI needs to read
129
+ * the playlist. **Phase 65** absorbs that step too.
130
+ */
131
+ export function useOpenPlaylist(): UseOpenPlaylistResult {
132
+ const {openPlayer} = usePlayerActivity();
133
+
134
+ const openPlaylist = useCallback(
135
+ async (
136
+ entries: PlayableEntry[],
137
+ opts: OpenPlaylistOptions = {},
138
+ ): Promise<boolean> => {
139
+ // Defensive: empty list is a no-op.
140
+ if (!entries || entries.length === 0) return false;
141
+
142
+ const type = opts.type ?? 'audio';
143
+
144
+ // Resolve the start index. If shuffle is on and no
145
+ // explicit startIndex, pick a random non-zero index.
146
+ // (If shuffle lands on 0 by chance, the first track plays
147
+ // first — that's fine, the shuffle just orders the rest.)
148
+ let startIndex = opts.startIndex ?? 0;
149
+ let orderedEntries: PlayableEntry[] = entries;
150
+
151
+ if (opts.shuffle) {
152
+ // Fisher-Yates shuffle a copy. Don't mutate the input.
153
+ orderedEntries = entries.slice();
154
+ for (let i = orderedEntries.length - 1; i > 0; i--) {
155
+ const j = Math.floor(Math.random() * (i + 1));
156
+ [orderedEntries[i], orderedEntries[j]] = [
157
+ orderedEntries[j],
158
+ orderedEntries[i],
159
+ ];
160
+ }
161
+ if (opts.startIndex == null) {
162
+ startIndex = Math.floor(Math.random() * orderedEntries.length);
163
+ }
164
+ }
165
+
166
+ // Clamp startIndex to the valid range. A consumer that
167
+ // passes `startIndex: 99` for a 3-entry list gets index 2.
168
+ if (startIndex < 0) startIndex = 0;
169
+ if (startIndex >= orderedEntries.length) {
170
+ startIndex = orderedEntries.length - 1;
171
+ }
172
+
173
+ const start = orderedEntries[startIndex];
174
+ if (!start) return false;
175
+
176
+ return openPlayer({
177
+ uri: start.uri,
178
+ title: start.title,
179
+ type,
180
+ startPositionMs: opts.startPositionMs,
181
+ ...(opts.startExtras as Partial<OpenPlayerOptions>),
182
+ });
183
+ },
184
+ [openPlayer],
185
+ );
186
+
187
+ return {openPlaylist};
188
+ }
@@ -0,0 +1,94 @@
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';
@@ -0,0 +1,57 @@
1
+ import {useStore} from 'zustand';
2
+ import {useShallow} from 'zustand/react/shallow';
3
+ import {
4
+ usePlayerQueueStore,
5
+ } from '../stores/playerQueueStore';
6
+ import type {
7
+ PlayerQueueItem,
8
+ PlayerQueueStore,
9
+ } from '../stores/playerQueueStore';
10
+
11
+ /**
12
+ * V15 Phase 65: the public hook for queue + playback-history state.
13
+ *
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.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * function QueueScreen() {
22
+ * const {queue, addToQueue, removeFromQueue} = useQueue();
23
+ * return <FlatList data={queue} ... />;
24
+ * }
25
+ *
26
+ * // For a single field (no re-render on other field changes):
27
+ * function QueueBadge() {
28
+ * const length = useQueueLength();
29
+ * return <Text>{length}</Text>;
30
+ * }
31
+ * ```
32
+ */
33
+ export function useQueue<T = PlayerQueueStore>(
34
+ selector?: (state: PlayerQueueStore) => T,
35
+ ): T {
36
+ if (selector) {
37
+ return useStore(usePlayerQueueStore, useShallow(selector));
38
+ }
39
+ return useStore(usePlayerQueueStore) as unknown as T;
40
+ }
41
+
42
+ /** Convenience hook: just the queue length. */
43
+ export function useQueueLength(): number {
44
+ return useStore(usePlayerQueueStore, state => state.queue.length);
45
+ }
46
+
47
+ /** Convenience hook: just the queue array. */
48
+ export function useQueueItems(): PlayerQueueItem[] {
49
+ return useStore(usePlayerQueueStore, state => state.queue);
50
+ }
51
+
52
+ /** Convenience hook: just the playback history array. */
53
+ export function usePlaybackHistory(): PlayerQueueItem[] {
54
+ return useStore(usePlayerQueueStore, state => state.playbackHistory);
55
+ }
56
+
57
+ export type {PlayerQueueItem, PlayerQueueStore} from '../stores/playerQueueStore';
@@ -0,0 +1,32 @@
1
+ import {useStore} from 'zustand';
2
+ import {usePlayerQueueSelectionStore} from '../stores/playerQueueSelectionStore';
3
+ import type {PlayerQueueSelectionStore} from '../stores/playerQueueSelectionStore';
4
+
5
+ /**
6
+ * V15 Phase 65: the public hook for queue multi-select state.
7
+ *
8
+ * Returns the full selection store: `{selectedIndices, setSelection, clearSelection, removeSelected, moveSelectedToTop}`.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * function QueueManagementSheet() {
13
+ * const {selectedIndices, setSelection, clearSelection} = useQueueSelection();
14
+ * // ... render multi-select UI
15
+ * }
16
+ * ```
17
+ */
18
+ export function useQueueSelection<T = PlayerQueueSelectionStore>(
19
+ selector?: (state: PlayerQueueSelectionStore) => T,
20
+ ): T {
21
+ if (selector) {
22
+ return useStore(usePlayerQueueSelectionStore, selector);
23
+ }
24
+ return useStore(usePlayerQueueSelectionStore) as unknown as T;
25
+ }
26
+
27
+ /** Convenience hook: just the selected indices. */
28
+ export function useQueueSelectedIndices(): number[] {
29
+ return useStore(usePlayerQueueSelectionStore, state => state.selectedIndices);
30
+ }
31
+
32
+ export type {PlayerQueueSelectionStore} from '../stores/playerQueueSelectionStore';
@@ -0,0 +1,58 @@
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
+ }
package/src/index.ts CHANGED
@@ -75,6 +75,47 @@ export {
75
75
  } from './hooks/useOpenWithResume';
76
76
 
77
77
  export {SimbaPlayer, type SimbaPlayerProps} from './hooks/SimbaPlayer';
78
+ export {
79
+ useSimbaPlayerLookup,
80
+ type GetResumePosition,
81
+ } from './hooks/useSimbaPlayerLookup';
82
+ export {SimbaPlayerRoot, type SimbaPlayerRootProps} from './hooks/SimbaPlayerRoot';
83
+ export {useOpenFromUrl} from './hooks/useOpenFromUrl';
84
+ export {
85
+ useOpenPlaylist,
86
+ type PlayableEntry,
87
+ type OpenPlaylistOptions,
88
+ type UseOpenPlaylistResult,
89
+ } from './hooks/useOpenPlaylist';
90
+ export {
91
+ useQueue,
92
+ useQueueLength,
93
+ useQueueItems,
94
+ usePlaybackHistory,
95
+ type PlayerQueueItem,
96
+ type PlayerQueueStore,
97
+ } from './hooks/useQueue';
98
+ export {
99
+ useQueueSelection,
100
+ useQueueSelectedIndices,
101
+ type PlayerQueueSelectionStore,
102
+ } 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';
78
119
  export {useLaunchParams} from './hooks/useLaunchParams';
79
120
 
80
121
  export {
@@ -0,0 +1,34 @@
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
+ }));