Skip to content

Instantly share code, notes, and snippets.

@areknawo
Created November 29, 2020 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save areknawo/e673c2671f72beb95dc48a4368961bb2 to your computer and use it in GitHub Desktop.
Save areknawo/e673c2671f72beb95dc48a4368961bb2 to your computer and use it in GitHub Desktop.
MusicKit JS TypeScript typings
/// <reference types="apple-music-api" />
// Requires @types/apple-music-api typings (https://www.npmjs.com/package/@types/apple-music-api)
/**
* MusicKit namespace.
*/
declare namespace MusicKit {
interface Resource extends AppleMusicApi.Resource {}
interface ActivityResource extends Resource {}
interface AlbumResource extends AppleMusicApi.Album {}
interface AppleCuratorResource extends AppleMusicApi.Curator {}
interface ArtistResource extends AppleMusicApi.Artist {}
interface ChartResource extends AppleMusicApi.Resource {}
interface CuratorResource extends AppleMusicApi.Curator {}
interface GenreResource extends AppleMusicApi.Genre {}
interface MusicVideoResource extends AppleMusicApi.Resource {}
interface PlaylistResource extends AppleMusicApi.Playlist {}
interface RecommendationResource extends AppleMusicApi.Resource {}
interface SongResource extends AppleMusicApi.Song {}
interface StationResource extends AppleMusicApi.Station {}
interface StorefrontResource extends AppleMusicApi.Resource {}
interface Artwork extends AppleMusicApi.Artwork {}
/**
* Configure a MusicKit instance.
* @param configuration - A dictionary of configuration options for the MusicKit instance.
* @returns - A configured MusicKit instance.
*/
function configure(configuration: Configuration): MusicKitInstance;
/**
* Returns the configured MusicKit instance.
*
*/
function getInstance(): MusicKitInstance;
/**
* A configuration for an app.
*/
interface AppConfiguration {
/**
* The build number of your app.
*/
build?: string;
/**
* A URL for your app icon.
*/
icon?: string;
/**
* The name of your app.
*/
name?: string;
/**
* The version of your app.
*/
version?: string;
}
/**
* A dictionary used to configure the MusicKit instance.
*/
interface Configuration {
/**
* A property that defines your app configuration.
*/
app: AppConfiguration;
/**
* The bit rate for this MusicKit configuration.
*/
bitrate?: PlaybackBitrate;
/**
* This property indicates whether you have explicitly enabled or disabled declarative markup.
*/
declarativeMarkup?: boolean;
/**
* The developer token to identify yourself as a trusted developer and member of the Apple Developer Program.
*/
developerToken?: string;
/**
* The current storefront for this MusicKit configuration.
*/
storefrontId?: string;
}
/**
* This object provides access to a player instance, and through the player instance, access to control playback.
*/
interface MusicKitInstance {
/**
* An instance of the MusicKit API.
*/
readonly api: API;
/**
* The current bit rate for the media player.
*/
readonly bitrate: PlaybackBitrate;
/**
* The developer token to identify yourself as a trusted developer and member of the Apple Developer Program.
*/
readonly developerToken: string;
/**
* A Boolean value indicating whether the user has authenticated and authorized the application for use.
*/
readonly isAuthorized: boolean;
/**
* A user token used to access personalized Apple Music content.
*/
readonly musicUserToken: string;
/**
* The current playback state of the music player.
*/
readonly playbackState: PlaybackStates;
/**
* A Boolean value that indicates if a playback target is available.
*/
readonly playbackTargetAvailable: boolean;
/**
* An instance of the MusicKit player.
*/
readonly player: Player;
/**
* The current storefront for the configured MusicKit instance.
*/
readonly storefrontId: string;
/**
* Add an event listener for a MusicKit instance by name.
* @param name - The name of the event.
* @param callback - The callback function to invoke when the event occurs.
*/
addEventListener(name: string, callback: Function): void;
addToLibrary(id: string, type: any): Promise<void>;
/**
* Returns a promise containing a music user token when a user has authenticated and authorized the app.
*
* @returns - Returns a promise that resolves with a musicUserToken.
*/
authorize(): Promise<string>;
/**
* Begins playing the media item at the specified index in the queue.
* @param index - The queue index to begin playing media.
* @returns - Returns the current media item position.
*/
changeToMediaAtIndex(index: number): Promise<number>;
/**
* Pauses playback of the media player.
*/
pause(): void;
/**
* Begins playback of the current media item.
*/
play(): Promise<number>;
playLater(options: SetQueueOptions): Promise<any>;
playNext(options: SetQueueOptions): Promise<any>;
/**
* Removes an event listener for a MusicKit instance by name.
* @param name - The name of the event.
* @param callback - The callback function to remove.
*/
removeEventListener(name: string, callback: Function): void;
/**
* Sets the playback point to a specified time.
* @param time - The time to set as the playback point.
*/
seekToTime(time: number): Promise<void>;
/**
* Sets a music player's playback queue using queue options.
* @param options - The option used to set the playback queue.
* @returns - Returns the current playback queue.
*/
setQueue(options: SetQueueOptions): Promise<Queue>;
/**
* Starts playback of the next media item in the playback queue.
* @returns - Returns the current media item position.
*/
skipToNextItem(): Promise<number>;
/**
* Starts playback of the previous media item in the playback queue.
* @returns - Returns the current media position.
*/
skipToPreviousItem(): Promise<number>;
/**
* Stops playback of the media player.
*/
stop(): void;
/**
* Unauthorizes the app for the current user.
*/
unauthorize(): Promise<void>;
}
/**
* A media player that represents the media player for a MusicKit instance.
*/
interface Player {
/**
* The current bit rate of the music player.
*/
readonly bitrate: PlaybackBitrate;
/**
* The music player has EME loaded.
*/
readonly canSupportDRM: boolean;
/**
* The current playback duration.
*/
readonly currentPlaybackDuration: number;
/**
* The current playback progress.
*/
readonly currentPlaybackProgress: number;
/**
* The current position of the playhead.
*/
readonly currentPlaybackTime: number;
readonly currentPlaybackTimeRemaining: number;
/**
* The current playback duration in hours and minutes.
*/
readonly formattedCurrentPlaybackDuration: number;
/**
* A Boolean value indicating whether the player is currently playing.
*/
readonly isPlaying: boolean;
/**
* The currently-playing media item, or the media item, within an queue, that you have designated to begin playback.
*/
readonly nowPlayingItem: MediaItem;
/**
* The index of the now playing item in the current playback queue.
*/
readonly nowPlayingItemIndex?: number;
/**
* The current playback rate for the player.
*/
readonly playbackRate: number;
/**
* The current playback state of the music player.
*/
readonly playbackState: PlaybackStates;
/**
* A Boolean value that indicates whether a playback target is available.
*/
readonly playbackTargetAvailable: boolean;
/**
* The current playback queue of the music player.
*/
readonly queue: Queue;
/**
* The current repeat mode of the music player.
*/
readonly repeatMode: PlayerRepeatMode;
/**
* The current shuffle mode of the music player.
*/
readonly shuffleMode: PlayerShuffleMode;
/**
* A number indicating the current volume of the music player.
*/
readonly volume: number;
/**
* Adds an event listener as a callback for an event name.
* @param name - The name of the event.
* @param callback - The callback function to invoke when the event occurs.
*/
addEventListener(name: string, callback: Function): void;
/**
* Begins playing the media item at the specified index in the queue immediately.
* @param index - The queue index to begin playing media.
* @returns - Returns the current media item position.
*/
changeToMediaAtIndex(index: number): Promise<number>;
/**
* Begins playing the media item in the queue immediately.
* @param descriptor - A descriptor can be a MusicKit.MediaItem instance or a string identifier.
* @returns - Returns the current media item position.
*/
changeToMediaItem(descriptor: descriptor): Promise<number>;
/**
* Sets the volume to 0.
*/
mute(): void;
/**
* Pauses playback of the current item.
*/
pause(): void;
/**
* Initiates playback of the current item.
* @returns - Returns the current media item position.
*/
play(): Promise<void>;
/**
* Prepares a music player for playback.
* @param descriptor - A descriptor can be a MusicKit.MediaItem instance or a string identifier.
*/
prepareToPlay(descriptor: descriptor): Promise<void>;
/**
* @param name - The name of the event.
* @param callback - The callback function to remove.
*/
removeEventListener(name: string, callback: Function): void;
/**
* Sets the playback point to a specified time.
* @param time - The time to set as the playback point.
*/
seekToTime(time: number): Promise<void>;
/**
* Displays the playback target picker if a playback target is available.
*/
showPlaybackTargetPicker(): void;
/**
* Starts playback of the next media item in the playback queue.
* @returns - Returns the current media item position.
*/
skipToNextItem(): Promise<number>;
/**
* Starts playback of the previous media item in the playback queue.
* @returns - Returns the current media item position.
*/
skipToPreviousItem(): Promise<number>;
/**
* Stops the currently playing media item.
*/
stop(): void;
}
/**
* The playback bit rate of the music player.
*/
enum PlaybackBitrate {
/**
* The bit rate is 256 kbps.
*/
HIGH = 256,
/**
* The bit rate is 64 kbps.
*/
STANDARD = 64,
}
/**
* The playback states of the music player.
*/
enum PlaybackStates {
/**
* This value indicates that playback of all media items in the queue has ended.
*/
completed,
/**
* This value indicates that playback of the media item has ended.
*/
ended,
/**
* This value indicates that loading of the media item has begun.
*/
loading,
/**
* This value indicates that the player has not attempted to start playback.
*/
none,
/**
* This value indicates that playback has been paused.
*/
paused,
/**
* This value indicates that the player is currently playing media.
*/
playing,
/**
* This value indicates that the player has started a seek operation.
*/
seeking,
/**
* This value indicates that the player is trying to fetch media data but cannot retrieve the data.
*/
stalled,
/**
* This value indicates that playback has been stopped.
*/
stopped,
/**
* This value indicates that playback is delayed pending the completion of another operation.
*/
waiting,
}
/**
* Possible values for the repeat mode for the music player.
*/
enum PlayerRepeatMode {
/**
* The current queue will be repeated.
*/
all,
/**
* No repeat mode specified.
*/
none,
/**
* The current media item will be repeated.
*/
one,
}
/**
* The shuffle mode for the music player.
*/
enum PlayerShuffleMode {
/**
* This value indicates that shuffle mode is off.
*/
off,
/**
* This value indicates that songs are being shuffled in the current queue.
*/
songs,
}
interface QueryParameters {
[key: string]: any;
}
/**
* This class represents the Apple Music API.
*/
class API {
/**
* An instance of the Cloud library.
*/
library: Library;
/**
* The storefront used for making calls to the API.
*/
storefrontId: string;
/**
* Fetch one or more activities using their identifiers.
* @param ids - An array of activity identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of activity resources.
*/
activities(
ids: string[],
parameters?: QueryParameters
): Promise<ActivityResource[]>;
/**
* Fetch an activity using its identifier.
* @param id - An activity identifier.
* @param parameters - A query params object that is serialized and passed directly to the Apple Music API.
* @returns - An activity resource.
*/
activity(
id: string,
parameters?: QueryParameters
): Promise<ActivityResource>;
/**
* Add a catalog resource to a user's library.
* @param parameters - A dictionary containing the items to add to the library.
*/
addToLibrary(parameters: any): Promise<void>;
/**
* Fetch an album using its identifier.
* @param id - An album identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An album resource.
*/
album(id: string, parameters?: QueryParameters): Promise<AlbumResource>;
/**
* Fetch one or more albums using their identifiers.
* @param ids - An array of album identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of album resources.
*/
albums(
ids: string[],
parameters?: QueryParameters
): Promise<AlbumResource[]>;
/**
* Fetch an Apple curator using its identifier.
* @param id - An Apple curator identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An Apple curator resource.
*/
appleCurator(
id: string,
parameters?: QueryParameters
): Promise<AppleCuratorResource>;
/**
* Fetch one or more Apple curators using their identifiers.
* @param ids - An array of Apple curator identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of Apple curator resources.
*/
appleCurators(
ids: string[],
parameters?: QueryParameters
): Promise<AppleCuratorResource[]>;
/**
* Fetch an artist using its identifier.
* @param id - An artist identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An artist resource.
*/
artist(id: string, parameters?: QueryParameters): Promise<ArtistResource>;
/**
* Fetch one or more artists using their identifiers.
* @param ids - An array of artist identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of artist resources.
*/
artists(
ids: string[],
parameters?: QueryParameters
): Promise<ArtistResource[]>;
/**
* Fetch one or more charts.
* @param types - An array of artist identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of chart resources.
*/
charts(
types: string[],
parameters?: QueryParameters
): Promise<ChartResource[]>;
/**
* Fetch a curator using its identifier.
* @param id - A curator identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - A curator resource.
*/
curator(id: string, parameters?: QueryParameters): Promise<CuratorResource>;
/**
* Fetch one or more curators using their identifiers.
* @param ids - An array of curator identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of curator resources.
*/
curators(
ids: string[],
parameters?: QueryParameters
): Promise<CuratorResource[]>;
/**
* Fetch a genre using its identifier.
* @param id - A genre identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - A genre resource.
*/
genre(id: string, parameters?: QueryParameters): Promise<GenreResource>;
/**
* Fetch one or more genres using their identifiers.
* @param ids - An array of genre identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of genre resources.
*/
genres(
ids: string[],
parameters?: QueryParameters
): Promise<GenreResource[]>;
/**
* Fetch the resources in heavy rotation for the user.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of resources.
*/
historyHeavyRotation(parameters: QueryParameters): Promise<Resource[]>;
/**
* Fetch a music video using its identifier.
* @param id - A music video identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - A music video resource.
*/
musicVideo(
id: string,
parameters?: QueryParameters
): Promise<MusicVideoResource>;
/**
* Fetch one or more music videos using their identifiers.
* @param ids - An array of music video identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of music video resources.
*/
musicVideos(
ids: string[],
parameters?: QueryParameters
): Promise<MusicVideoResource[]>;
/**
* Fetch a playlist using its identifier.
* @param id - A playlist identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - A playlist resource.
*/
playlist(
id: string,
parameters?: QueryParameters
): Promise<PlaylistResource>;
/**
* Fetch one or more playlists using their identifiers.
* @param ids - An array of playlist identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of playlist resources.
*/
playlists(
ids: string[],
parameters?: QueryParameters
): Promise<PlaylistResource[]>;
/**
* Fetch the recently played resources for the user.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of resources.
*/
recentPlayed(parameters: QueryParameters): Promise<Resource[]>;
/**
* Fetch a recommendation using its identifier.
* @param id - A recommendation identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - A recommendation resource.
*/
recommendation(
id: string,
parameters?: QueryParameters
): Promise<RecommendationResource>;
/**
* Fetch one or more recommendations using their identifiers.
* @param ids - An array of recommendation identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of recommendation resources.
*/
recommendations(
ids: string[],
parameters?: QueryParameters
): Promise<RecommendationResource[]>;
/**
* Search the catalog using a query.
* @param term - The term to search.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of resources.
*/
search(term: string, parameters?: QueryParameters): Promise<Resource[]>;
/**
* Fetch the search term results for a hint.
* @param term - The term to search.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of resources.
*/
searchHints(term: string, parameters?: QueryParameters): Promise<Resource[]>;
/**
* Fetch a song using its identifier.
* @param id - A song identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - A song resource.
*/
song(id: string, parameters?: QueryParameters): Promise<SongResource>;
/**
* Fetch one or more songs using their identifiers.
* @param ids - An array of song identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of song resources.
*/
songs(ids: string[], parameters?: QueryParameters): Promise<SongResource[]>;
/**
* Fetch a station using its identifier.
* @param id - A station identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - A station resource.
*/
station(id: string, parameters?: QueryParameters): Promise<StationResource>;
/**
* Fetch one or more stations using their identifiers.
* @param ids - An array of station identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of station resources.
*/
stations(
ids: string[],
parameters?: QueryParameters
): Promise<StationResource[]>;
/**
* Fetch a storefront using its identifier.
* @param id - A storefront identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - A storefront resource.
*/
storefront(
id: string,
parameters?: QueryParameters
): Promise<StorefrontResource>;
/**
* Fetch one or more storefronts using their identifiers.
* @param ids - An array of storefront identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Apple Music API.
* @returns - An array of storefront resources.
*/
storefronts(
ids: string[],
parameters?: QueryParameters
): Promise<StorefrontResource[]>;
}
/**
* This class represents a user's Cloud Library.
*/
class Library {
/**
* Fetch a library album using its identifier.
* @param id - A library album identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Cloud Library API.
* @returns - A library album resource.
*/
album(id: string, parameters?: QueryParameters): Promise<AlbumResource>;
/**
* Fetch one or more library albums using their identifiers.
* @param ids - An array of library album identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Cloud Library API.
* @returns - An array of library album resources.
*/
albums(
ids: string[] | null,
parameters?: QueryParameters
): Promise<AlbumResource[]>;
/**
* Fetch a library artist using its identifier.
* @param id - A library artist identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Cloud Library API.
* @returns - A library artist resource.
*/
artist(id: string, parameters?: QueryParameters): Promise<ArtistResource>;
/**
* Fetch one or more library artists using their identifiers.
* @param ids - An array of library artist identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Cloud Library API.
* @returns - An array of library artist resources.
*/
artists(
ids: string[] | null,
parameters?: QueryParameters
): Promise<ArtistResource[]>;
/**
* Fetch a library music video using its identifier.
* @param id - A library music video identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Cloud Library API.
* @returns - A library music video resource.
*/
musicVideo(
id: string,
parameters?: QueryParameters
): Promise<MusicVideoResource>;
/**
* Fetch one or more library music videos using their identifiers.
* @param ids - An array of library music video identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Cloud Library API.
* @returns - An array of library music video resources.
*/
musicVideos(
ids: string[] | null,
parameters?: QueryParameters
): Promise<MusicVideoResource[]>;
/**
* Fetch a library playlist using its identifier.
* @param id - A library playlist identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Cloud Library API.
* @returns - A library playlist resource.
*/
playlist(
id: string,
parameters?: QueryParameters
): Promise<PlaylistResource>;
/**
* Fetch one or more library playlists using their identifiers.
* @param ids - An array of library playlist identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Cloud Library API.
* @returns - An array of library playlist resources.
*/
playlists(
ids: string[] | null,
parameters?: QueryParameters
): Promise<PlaylistResource[]>;
/**
* Search the library using a query.
* @param term - The term to search.
* @param parameters - A query parameters object that is serialized and passed directly to the Cloud Library API.
* @returns - An array of library resources.
*/
search(term: string, parameters?: QueryParameters): Promise<Resource>;
/**
* Fetch a library song using its identifier.
* @param id - A library song identifier.
* @param parameters - A query parameters object that is serialized and passed directly to the Cloud Library API.
* @returns - A library song resource.
*/
song(id: string, parameters?: QueryParameters): Promise<SongResource>;
/**
* Fetch one or more library songs using their identifiers.
* @param ids - An array of library song identifiers.
* @param parameters - A query parameters object that is serialized and passed directly to the Cloud Library API.
* @returns - An array of library song resources.
*/
songs(
ids: string[] | null,
parameters?: QueryParameters
): Promise<SongResource[]>;
}
/**
* This class represents a single media item.
*/
class MediaItem {
/**
* A constructor that creates a new media item from specified options.
* @param options - The options to use when defining a media item.
* @returns - A media item.
*/
constructor(options: MediaItemOptions);
/**
* A string of information about the album.
*/
readonly albumInfo: string;
/**
* The title of the album.
*/
readonly albumName: string;
/**
* The artist for a media item.
*/
readonly artistName: string;
/**
* The artwork object for the media item.
*/
readonly artwork: Artwork;
/**
* The artwork image for the media item.
*/
readonly artworkURL: string;
/**
* The attributes object for the media item.
*/
readonly attributes: { [attribute: string]: any };
/**
* A string containing the content rating for the media item.
*/
readonly contentRating: string;
/**
* The disc number where the media item appears.
*/
readonly discNumber: number;
/**
* The identifier for the media item.
*/
readonly id: string;
/**
* A string of common information about the media item.
*/
readonly info: string;
/**
* A Boolean value that indicates whether the item has explicit lyrics or language.
*/
readonly isExplicitItem: boolean;
/**
* A Boolean value that indicated whether the item is playable.
*/
readonly isPlayable: boolean;
/**
* A Boolean value indicating whether the media item is prepared to play.
*/
readonly isPreparedToPlay: boolean;
/**
* The ISRC (International Standard Recording Code) for a media item.
*/
readonly isrc: string;
/**
* The playback duration of the media item.
*/
readonly playbackDuration: number;
readonly playlistArtworkURL: string;
readonly playlistName: string;
/**
* The URL to an unencrypted preview of the media item.
*/
readonly previewURL: string;
/**
* The release date of the media item.
*/
readonly releaseDate?: Date;
/**
* The name of the media item.
*/
readonly title: string;
/**
* The number of the media item in the album's track list.
*/
readonly trackNumber: number;
/**
* The type of the media item.
*/
readonly type: any;
/**
* Prepares a media item for playback.
*/
prepareToPlay(): Promise<void>;
}
/**
* The options to use when defining a media item.
*/
interface MediaItemOptions {
/**
* The attributes for the media item.
*/
attributes: any;
/**
* The identifier for the media item.
*/
id?: string;
/**
* The type for the media item.
*/
type: any;
}
/**
* This property describes a media item.
*/
type descriptor = MediaItem | string;
/**
* An array of media items to be played.
*/
interface Queue {
/**
* A Boolean value indicating whether the queue has no items.
*/
readonly isEmpty: boolean;
/**
* An array of all the media items in the queue.
*/
readonly items: MediaItem[];
/**
* The number of items in the queue.
*/
readonly length: number;
/**
* The next playable media item in the queue.
*/
readonly nextPlayableItem?: MediaItem;
/**
* The current queue position.
*/
readonly position: number;
/**
* The previous playable media item in the queue.
*/
readonly previousPlayableItem?: MediaItem;
/**
* Add an event listener for a MusicKit queue by name.
* @param name - The name of the event.
* @param callback - The callback function to invoke when the event occurs.
*/
addEventListener(name: string, callback: Function): void;
/**
* Inserts the media items defined by the queue descriptor after the last media item in the current queue.
* @param descriptor - A queue descriptor.
*/
append(descriptor: descriptor): void;
/**
* Returns the index in the playback queue for a media item descriptor.
* @param descriptor - A descriptor can be an instance of the MusicKit.MediaItem class, or a string identifier.
* @returns - The index of the media item.
*/
indexForItem(descriptor: descriptor): number;
/**
* Returns the media item located in the indicated array index.
* @param index - The array index for the media item.
* @returns - The media item at the index.
*/
item(index: number): MediaItem;
/**
* Inserts the media items defined by the queue descriptor into the current queue immediately after the currently playing media item.
* @param descriptor - A queue descriptor.
*/
prepend(descriptor: descriptor): void;
/**
* Removes an event listener for a MusicKit queue by name.
* @param name - The name of the event.
* @param callback - The callback function to remove.
*/
removeEventListener(name: string, callback: Function): void;
}
/**
* The options to use when setting a music player's playback queue.
*/
interface SetQueueOptions {
/**
* The catalog album used to set a music player's playback queue.
*/
album?: string;
/**
* The media items used to set a music player's playback queue.
*/
items?: descriptor[];
/**
* The parameters used to set a music player's playback queue.
*/
parameters?: QueryParameters;
/**
* The playlist used to set a music player's playback queue.
*/
playlist?: string;
/**
* The song used to set a music player's playback queue.
*/
song?: string;
/**
* The songs used to set a music player's playback queue.
*/
songs?: string[];
/**
* The start position for a set playback queue.
*/
startPosition?: number;
/**
* A content URL used to set a music player's playback queue.
*/
url?: string;
}
/**
* A class that describes an error that may occur when using MusicKit JS, including server and local errors.
*/
class MKError {
/**
* Error code indicating that you don't have permission to access the endpoint, media item, or content.
*/
ACCESS_DENIED: string;
/**
* Error code indicating the authorization was rejected.
*/
AUTHORIZATION_ERROR: string;
/**
* Error code indicating a MusicKit JS configuration error.
*/
CONFIGURATION_ERROR: string;
/**
* Error code indicating you don't have permission to access this content, due to content restrictions.
*/
CONTENT_RESTRICTED: string;
/**
* Error code indicating the parameters provided for this method are invalid.
*/
INVALID_ARGUMENTS: string;
/**
* Error code indicating that the VM certificate could not be applied.
*/
MEDIA_CERTIFICATE: string;
/**
* Error code indicating that the media item descriptor is invalid.
*/
MEDIA_DESCRIPTOR: string;
/**
* Error code indicating that a DRM key could not be generated.
*/
MEDIA_KEY: string;
/**
* Error code indicating a DRM license error.
*/
MEDIA_LICENSE: string;
/**
* Error code indicating a media playback error.
*/
MEDIA_PLAYBACK: string;
/**
* Error code indicating that an EME session could not be created.
*/
MEDIA_SESSION: string;
/**
* Error code indicating a network error.
*/
NETWORK_ERROR: string;
/**
* Error code indicating that the resource was not found.
*/
NOT_FOUND: string;
/**
* Error code indicating that you have exceeded the Apple Music API quota.
*/
QUOTA_EXCEEDED: string;
SERVER_ERROR: string;
/**
* Error code indicating the MusicKit service could not be reached.
*/
SERVICE_UNAVAILABLE: string;
/**
* Error code indicating that the user's Apple Music subscription has expired.
*/
SUBSCRIPTION_ERROR: string;
/**
* Error code indicating an unknown error.
*/
UNKNOWN_ERROR: string;
/**
* Error code indicating that the operation is not supported.
*/
UNSUPPORTED_ERROR: string;
/**
* A description of the error that occurred.
*/
description?: string;
/**
* The error code for this error.
*/
errorCode: string;
}
/**
* Returns a formatted artwork URL.
* @param artwork - An artwork resource object.
* @param height - The desired artwork height.
* @param width - the desired artwork width.
* @returns - A formatted artwork URL.
*/
function formatArtworkURL(
artwork: Artwork,
height?: number,
width?: number
): string;
/**
* Returns an object with milliseconds formatted into hours and minutes.
* @param milliseconds - The number of milliseconds.
* @returns - An object containing hours and minutes properties that equal the number of milliseconds.
*/
function formattedMilliseconds(
milliseconds: number
): {
hours: number;
minutes: number;
};
/**
* Returns an object with seconds formatted into hours and minutes.
* @param seconds - The number of seconds.
* @returns - An object containing hours and minutes properties that equal the number of seconds.
*/
function formattedSeconds(
seconds: number
): {
hours: number;
minutes: number;
};
/**
* Generates Apple Music web player markup.
* @param url - The iTunes URL for the Apple Music content.
* @param options - The object containing the height and width of the player. The default value is {height: '450px', width: '660px'.
* @returns - A string containing the Apple Music web player markup.
*/
function generateEmbedCode(
url: string,
options: {
height: number | string;
width: number | string;
}
): string;
interface Events {
/**
* A notification name indicating a change in the authorization status.
*/
authorizationStatusDidChange: string;
/**
* A notification name indicating an upcoming change in the authorization status.
*/
authorizationStatusWillChange: string;
/**
* A notification name indicating a user is eligible for a subscribe view.
*/
eligibleForSubscribeView: string;
/**
* A notification name indicating MusicKit JS is loaded.
*/
loaded: string;
/**
* A notification name indicating the player has obtained enough data for playback to start.
*/
mediaCanPlay: string;
/**
* A notification name indicating that the currently-playing media item has changed.
*/
mediaItemDidChange: string;
/**
* A notification name indicating the currently-playing media item is about to change.
*/
mediaItemWillChange: string;
/**
* A notification name indicating that the player has thrown an error during playback.
*/
mediaPlaybackError: string;
/**
* A notification name indicating the media item's metadata has finished loading.
*/
metadataDidChange: string;
/**
* A notification indicating the playback bit rate has changed.
*/
playbackBitrateDidChange: string;
/**
* A notification name indicating the current playback duration changed.
*/
playbackDurationDidChange: string;
/**
* A notification name indicating the current playback progress changed.
*/
playbackProgressDidChange: string;
/**
* A notification indicating the playback state has changed.
*/
playbackStateDidChange: string;
/**
* A notification indicating the playback state is about to be changed.
*/
playbackStateWillChange: string;
/**
* A notification indicating that a playback target's availability has changed .
*/
playbackTargetAvailableDidChange: string;
/**
* A notification name indicating the current playback time has changed.
*/
playbackTimeDidChange: string;
/**
* A notification name indicating the player volume has changed.
*/
playbackVolumeDidChange: string;
/**
* A notification name indicating the playback has started in another context on your domain, and the current player has stopped playback.
*/
primaryPlayerDidChange: string;
/**
* A notification name indicating that the items in the current playback queue have changed.
*/
queueItemsDidChange: string;
/**
* A notification name indicating that the current queue position has changed.
*/
queuePositionDidChange: string;
/**
* A notification name indicating a change in the storefront country code.
*/
storefrontCountryCodeDidChange: string;
/**
* A notification name indicating that the device's inferred storefront identifier changed.
*/
storefrontIdentifierDidChange: string;
/**
* A notification name indicating the user token changed.
*/
userTokenDidChange: string;
}
const errors: MKError[];
function formatMediaType(seconds: number, separator: string): string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment