@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
140 lines • 5.12 kB
TypeScript
import type { EventSubscription } from "expo-modules-core";
import { SpotifyURI } from "../uri";
export type { PlayerErrorCode } from "./error";
export { PlayerError } from "./error";
/** Repeat mode for the Spotify player. */
export type RepeatMode = 0 /** off */ | 1 /** repeat current track */ | 2; /** repeat current context */
/** Valid podcast playback speed multipliers. */
export type PodcastPlaybackSpeed = 0.5 | 0.8 | 1.0 | 1.2 | 1.5 | 2.0 | 3.0;
/** A Spotify artist. */
export interface Artist {
name: string;
uri: string;
}
/** A Spotify album. */
export interface Album {
name: string;
uri: string;
}
/** A track currently loaded in the Spotify player. */
export interface Track {
uri: string;
name: string;
/** Identifier used by `Images.load(...)`. */
imageIdentifier?: string;
/** Duration in milliseconds. */
duration: number;
artist: Artist;
album: Album;
isSaved: boolean;
isEpisode: boolean;
isPodcast: boolean;
isAdvertisement: boolean;
}
/** Current playback options (shuffle / repeat). */
export interface PlaybackOptions {
isShuffling: boolean;
/** 0 = off, 1 = repeat track, 2 = repeat context. */
repeatMode: RepeatMode;
}
/** Actions currently permitted by Spotify (gate UI buttons on these). */
export interface PlaybackRestrictions {
canSkipNext: boolean;
canSkipPrevious: boolean;
canRepeatTrack: boolean;
canRepeatContext: boolean;
canToggleShuffle: boolean;
canSeek: boolean;
}
/** Full snapshot of the Spotify player at a point in time. */
export interface PlayerState {
track: Track;
/** Current playback position in milliseconds. */
playbackPosition: number;
playbackSpeed: number;
isPaused: boolean;
playbackOptions: PlaybackOptions;
playbackRestrictions: PlaybackRestrictions;
contextTitle: string;
contextUri: string;
}
/** Crossfade configuration from the Spotify app. */
export interface CrossfadeState {
isEnabled: boolean;
/** Crossfade duration in milliseconds (only meaningful when enabled). */
duration: number;
}
/**
* Spotify Player namespace. Transport controls, queue management, and
* player-state subscriptions. Requires `AppRemote.connect()` to be resolved
* before any call.
*
* @example
* ```ts
* import { Player, SpotifyURI } from "@wwdrew/expo-spotify-sdk";
*
* await Player.play(SpotifyURI.from("spotify:track:4uLU6hMCjMI75M1A2tKUQC"));
* const state = await Player.getPlayerState();
*
* const sub = Player.addListener("playerStateChange", (state) => {
* console.log("now playing:", state.track.name, "paused:", state.isPaused);
* });
* ```
*/
export declare const Player: {
/**
* Asks Spotify to play the entity identified by the given URI.
* Requires Spotify Premium for on-demand track playback; throws
* `PlayerError("PREMIUM_REQUIRED", ...)` for Free users.
*/
readonly play: (uri: SpotifyURI) => Promise<void>;
/** Pauses playback. */
readonly pause: () => Promise<void>;
/** Resumes paused playback. */
readonly resume: () => Promise<void>;
/** Skips to the next track in the queue or context. */
readonly skipNext: () => Promise<void>;
/** Skips to the previous track. */
readonly skipPrevious: () => Promise<void>;
/**
* Seeks to the given position in milliseconds.
* Only valid when `PlaybackRestrictions.canSeek` is `true`.
*/
readonly seekTo: (positionMs: number) => Promise<void>;
/** Enables or disables shuffle. */
readonly setShuffle: (enabled: boolean) => Promise<void>;
/**
* Sets the repeat mode.
* @param mode 0 = off, 1 = repeat track, 2 = repeat context.
*/
readonly setRepeatMode: (mode: RepeatMode) => Promise<void>;
/**
* Sets the podcast playback speed. Only takes effect when a podcast episode
* is playing; valid speeds are `0.5 | 0.8 | 1.0 | 1.2 | 1.5 | 2.0 | 3.0`.
*/
readonly setPodcastPlaybackSpeed: (speed: PodcastPlaybackSpeed) => Promise<void>;
/** Adds a track URI to the end of the current playback queue. */
readonly queue: (uri: SpotifyURI) => Promise<void>;
/** Returns the current {@link PlayerState} as a one-shot pull. */
readonly getPlayerState: () => Promise<PlayerState>;
/** Returns the current {@link CrossfadeState} as a one-shot pull. */
readonly getCrossfadeState: () => Promise<CrossfadeState>;
/**
* Subscribes to player state changes. The callback fires whenever the
* Spotify app reports a state update (track change, pause/resume, seek,
* shuffle/repeat change, etc.).
*
* Returns a `Subscription` — call `.remove()` to unsubscribe.
*
* @example
* ```ts
* const sub = Player.addListener("playerStateChange", (state) => {
* console.log("track:", state.track.name, "paused:", state.isPaused);
* });
* // ...later:
* sub.remove();
* ```
*/
readonly addListener: (event: "playerStateChange", listener: (state: PlayerState) => void) => EventSubscription;
};
//# sourceMappingURL=index.d.ts.map