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

46 lines 1.58 kB
// --------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------- import ExpoSpotifySDKModule from "../ExpoSpotifySDKModule"; import { createNativeErrorRethrow } from "../internal/native-errors"; import { ImagesError } from "./error"; export { ImagesError } from "./error"; const rethrowAsImagesError = createNativeErrorRethrow({ ErrorClass: ImagesError, unknownCode: "UNKNOWN", validCodes: new Set([ "NOT_CONNECTED", "INVALID_URI", "IMAGE_LOAD_FAILED", "UNKNOWN", ]), }); function getImageIdentifier(item) { const value = item?.imageIdentifier; if (!value || !value.trim()) { throw new ImagesError("INVALID_URI", "Images.load(): item does not contain a valid imageIdentifier"); } return value; } /** * Spotify Images namespace. Fetches cover art for tracks, albums, artists, * and content items via the App Remote SDK, writing the bitmap to a temp file * and returning its local URI. Requires `AppRemote.connect()` to be resolved. * * @example * ```ts * import { Images } from "@wwdrew/expo-spotify-sdk"; * * const { uri } = await Images.load(track, "large"); * ``` */ export const Images = { /** * Loads a Spotify image and returns a local file URI. */ load(item, size) { const imageIdentifier = getImageIdentifier(item); return ExpoSpotifySDKModule.imagesLoad(imageIdentifier, size).catch(rethrowAsImagesError); }, }; //# sourceMappingURL=index.js.map