import { PlaybackBitrate, PlaybackStates, PlayerRepeatMode, PlayerShuffleMode } from './enums'; import type { MusicKitAPI } from './MusicKitAPI.d.ts'; export type MediaItem = object; export interface Queue { /** * The item at the `position` within `items` array */ 'currentItem': MediaItem; /** * True if the `length` of the queue is `0` */ 'isEmpty': boolean; /** * Array of `MediaItem`s in queue */ 'items': MediaItem[]; /** * The number of `MediaItem`s in the queu */ 'length': number; /** * The next item after the `currentItem` in the queue */ 'nextPlayableItem': MediaItem; /** * The current index of the queue */ 'position': number; /** * The previous item after the `currentItem` in the queue */ 'previousPlayableItem': MediaItem; } /** * Used to set what is to be played */ export interface QueueOptions { 'album'?: string; 'albums'?: string[]; 'musicVideo'?: string; 'musicVideos'?: string[]; 'playlist'?: string; 'playlists'?: string[]; 'song'?: string; 'songs'?: string[]; /** * Set the repeat mode when setting the queue */ 'repeatMode'?: PlayerRepeatMode; /** * Whether or not to start playing */ 'startPlaying'?: boolean; /** * The number of seconds to seek to in the current item */ 'startTime'?: number; } export interface SeekSeconds { 'BACK': number; 'FORWARD': number; } export interface MusicKitInstance { /** * Access the Apple Music API */ 'api': Readonly; /** * The current bitrate */ 'bitrate': Readonly; /** * The duration of the `nowPlayingItem`, in seconds */ 'currentPlaybackDuration': Readonly; /** * Percentage of playback completion of `nowPlayingItem`, between 0 and 1 */ 'currentPlaybackProgress': Readonly; /** * The playhead position for the `nowPlayingItem`, in seconds */ 'currentPlaybackTime': Readonly; /** * The remaining playback time for the `nowPlayingItem`, in seconds */ 'currentPlaybackTimeRemaining': Readonly; /** * Set to true if user successfully signed in and authorized application via `authorize` */ 'isAuthorized': Readonly; /** * True if audio is currently playing */ 'isPlaying': Readonly; /** * The current MediaItem that is playing */ 'nowPlayingItem': Readonly; /** * The index in the queue of the `nowPlayingItem` */ 'nowPlayingItemIndex': Readonly; /** * The speed of playback, default is 1.0 */ 'playbackRate': Readonly; /** * The state of playback, for more information. */ 'playbackState': Readonly; /** * If a user is not subscribed to Apple Music */ 'previewOnly': Readonly; /** * The current playback queue */ 'queue': Readonly; /** * True if the playback queue is empty */ 'queueIsEmpty': Readonly; /** * Repeat mode for the player. Set here to control mode */ 'repeatMode': PlayerRepeatMode; /** * Used to configure seek behaviour, in seconds */ 'seekSeconds': SeekSeconds | undefined; /** * Control the shuffle mode for the player */ 'shuffleMode': PlayerShuffleMode; /** * The id of the authorized user's storefront */ 'storefrontCountryCode': Readonly; /** * The storefrontId as configured for this `MusicKitInstance` */ 'storefrontId': Readonly; /** * Set this to allow for playing music videos in the specified element. */ 'videoContainerElement': HTMLVideoElement | undefined; /** * The volume of the `HTMLMediaElement`, between 0 and 1 */ 'volume': number; /** * Listen to an event on the `MusicKitInstance` * @param name - The Event name, see https://js-cdn.music.apple.com/musickit/v3/docs/index.html?path=/story/reference-javascript-events--page * @param callback - a callable function, whose arguments depend on the event listened to * @param options - Any further options (currently only 'once', which, if set to true, removes the listener after it was triggered once) */ 'addEventListener': ( name: string, callback: CallableFunction, options: { 'once': boolean } ) => void; /** * Authorize a user * @returns Promise resolving to string representing user, or if authorization failed, undefined */ 'authorize': () => Promise; /** * Play `MediaItem` at specified index in Queue * @param index - The index to play at */ 'changeToMediaAtIndex': ( index: number ) => Promise; /** * Change to a `MediaItem` or `string` representation of one instead of index * @param descriptor - The item */ 'changeToMediaItem': ( descriptor: MediaItem | string ) => Promise; /** * Change the user's storefront to `storefrontId`` * @param storefrontId - The storefront to change to */ 'changeUserStorefront': ( storefrontId: string ) => Promise; /** * Clears the queue */ 'clearQueue': () => Promise; /** * Close full-screen element, when applicable */ 'exitFullscreen': () => void; /** * Sets `volume` to `0`, previous value is stored */ 'mute': () => void; /** * Pause playback */ 'pause': () => void; /** * Starts playback of `nowPlayingItem` */ 'play': () => void; /** * Inserts the `MediaItem`(s) defined by `QueueOptions` at the position indicated in the current queue. * @param position - The index at which to insert * @param options - What to add to the queue */ 'playAt': ( position: number, options: QueueOptions ) => Promise; /** * Inserts the item(s) after the last item in the current queue * @param options - What to add to the queue */ 'playLater': ( options: QueueOptions ) => Promise; /** * Inserts the item(s) after the `nowPlayingItem` * @param options - What to add to the queue * @param clear - Whether or not to clear the queue again */ 'playNext': ( options: QueueOptions, clear?: boolean ) => Promise; /** * Remove the event listener again * @param name - The name of the event to remove for * @param callback - The used callback function on addEventListener */ 'removeEventListener': ( name: string, callback: CallableFunction ) => void; /** * Make element full-screen * @param element - The element to make full-screen */ 'requestFullscreen': ( element: HTMLElement ) => void; /** * Seeks back `seekSeconds.BACK` seconds */ 'seekBackward': () => Promise; /** * Seeks forward `seekSeconds.BACK` seconds */ 'seekForward': () => Promise; /** * Seek to a specific time in the song * @param time - the time in seconds to move to */ 'seekToTime': ( time: number ) => Promise; /** * Set items for the playback queue * @param options - Description of what is to be added to the queue */ 'setQueue': ( options: QueueOptions ) => Promise; /** * Skip to next song in queue */ 'skipToNextItem': () => Promise; /** * Skip to previous song in queue */ 'skipToPreviousItem': () => Promise; /** * Stops the `nowPlayingItem` */ 'stop': () => void; /** * Unauthorizes the user from the application */ 'unauthorize': () => Promise; /** * Unmute playback volume, setting it to value before muting */ 'unmute': () => void; }