UNPKG

@wwdrew/expo-spotify-sdk

Version:

Expo module wrapping the native Spotify iOS (v5) and Android (v4) SDKs for OAuth authentication and App Remote playback control

90 lines 3.43 kB
import { type ConnectionState } from "../app-remote"; import { type SpotifySession } from "../auth"; import { type PlayerState, type Track } from "../player"; import type { SpotifyURI as SpotifyURIType } from "../uri"; import { type Capabilities, type LibraryState } from "../user"; /** * Returns the current Spotify OAuth session, or `null` when not authenticated. * Updates automatically whenever `Auth.authenticate()` or `Auth.refresh()` * resolves, and on session failure. * * Built on `useSyncExternalStore` for tearing-free React rendering. */ export declare function useSession(): SpotifySession | null; /** * Returns the current App Remote {@link ConnectionState} * (`"disconnected"` | `"connecting"` | `"connected"`). Updates automatically * on every state transition driven by `AppRemote.connect()` and `disconnect()`. * * Built on `useSyncExternalStore` for tearing-free React rendering. * * @example * ```tsx * function ConnectionBanner() { * const state = useConnectionState(); * return <Text>{state === "connected" ? "Connected" : "Disconnected"}</Text>; * } * ``` */ export declare function useConnectionState(): ConnectionState; /** * Returns the latest {@link PlayerState} from the Spotify app, or `null` * before the first update arrives (i.e., before `AppRemote.connect()` resolves * and the native subscription emits its first event). * * Updates on every state change reported by the Spotify app (track change, * pause/resume, seek, shuffle/repeat toggle, etc.). * * Built on `useSyncExternalStore` for tearing-free React rendering. * * @example * ```tsx * function NowPlaying() { * const state = usePlayerState(); * if (!state) return <Text>Not playing</Text>; * return <Text>{state.track.name} — {state.isPaused ? "Paused" : "Playing"}</Text>; * } * ``` */ export declare function usePlayerState(): PlayerState | null; /** * Returns the currently playing {@link Track}, or `null` when nothing is * playing or before the first state update arrives. * * Derived from `usePlayerState`. */ export declare function useCurrentTrack(): Track | null; /** * Returns `true` when the Spotify player is actively playing (not paused), * and `false` otherwise (including before the first state update arrives). * * Derived from `usePlayerState`. */ export declare function useIsPlaying(): boolean; /** * Returns the current playback position in milliseconds. Returns `0` before * the first state update arrives. * * **Note:** This value updates whenever the native side emits a player state * change (track transitions, pause/resume, seek, etc.) — not on a fixed timer. * For a progress bar that ticks smoothly, combine this with a local `Date.now` * offset and `requestAnimationFrame`. * * Derived from `usePlayerState`. */ export declare function usePlaybackPosition(): number; /** * Returns the latest Spotify user capabilities, or `null` before the first * snapshot arrives. * * Derived from `User.getCapabilities()` + `User.addListener("capabilitiesChange")`. */ export declare function useCapabilities(): Capabilities | null; /** * Returns the library state for a specific URI, or `null` before the first * snapshot arrives. * * Derived from `User.getLibraryState(uri)` + `User.addLibraryStateListener(uri, ...)`. */ export declare function useLibraryState(uri: SpotifyURIType): LibraryState | null; //# sourceMappingURL=index.d.ts.map