├── .editorconfig ├── .gitignore ├── .prettierrc ├── .travis.yml ├── LICENSE ├── MusicKit ├── MusicKit.API.d.ts ├── MusicKit.Events.d.ts ├── MusicKit.Library.d.ts ├── MusicKit.MKError.d.ts ├── MusicKit.MediaItem.d.ts ├── MusicKit.MusicKitInstance.d.ts ├── MusicKit.Player.d.ts ├── MusicKit.Queue.d.ts ├── MusicKit.SetQueueOptions.d.ts ├── MusicKit.d.ts └── index.d.ts ├── NOTICE ├── README.md ├── package.json ├── scripts └── update-version ├── test └── MusicKit-test.ts ├── tsconfig.json └── tslint.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | .npmrc 4 | *.log 5 | coverage 6 | package-lock.json 7 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all", 4 | "printWidth": 100 5 | } 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - node 4 | cache: npm 5 | install: 6 | - npm install 7 | script: 8 | - npm test 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Waseem Dahman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MusicKit/MusicKit.API.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for MusicKit JS 1.2.3 2 | // Project: https://developer.apple.com/documentation/musickitjs 3 | // Definitions by: Waseem Dahman 4 | 5 | declare namespace MusicKit { 6 | /** 7 | * This class represents the Apple Music API. 8 | */ 9 | interface API { 10 | /** 11 | * An instance of the Cloud library. 12 | */ 13 | library: Library; 14 | /** 15 | * The storefront used for making calls to the API. 16 | */ 17 | storefrontId: string; 18 | /** 19 | * Fetch one or more activities using their identifiers. 20 | * 21 | * @param ids An array of activity identifiers. 22 | * @param parameters A query parameters object that is serialized and passed 23 | * directly to the Apple Music API. 24 | */ 25 | activities(ids: string[], parameters?: QueryParameters): Promise; 26 | /** 27 | * Fetch an activity using its identifier. 28 | * 29 | * @param id An activity identifier. 30 | * @param parameters A query params object that is serialized and passed 31 | * directly to the Apple Music API. 32 | */ 33 | activity(id: string, parameters?: QueryParameters): Promise; 34 | /** 35 | * Add a catalog resource to a user's library. 36 | */ 37 | addToLibrary(parameters?: AddToLibraryParameters): Promise; 38 | /** 39 | * Fetch an album using its identifier. 40 | * 41 | * @param id An album identifier. 42 | * @param parameters A query parameters object that is serialized and passed 43 | * directly to the Apple Music API. 44 | */ 45 | album(id: string, parameters?: QueryParameters): Promise; 46 | /** 47 | * Fetch one or more albums using their identifiers. 48 | * 49 | * @param ids An array of album identifiers. 50 | * @param parameters A query parameters object that is serialized and passed 51 | * directly to the Apple Music API. 52 | */ 53 | albums(ids: string[], parameters?: QueryParameters): Promise; 54 | /** 55 | * Fetch an Apple curator using its identifier. 56 | * 57 | * @param id An Apple curator identifier. 58 | * @param parameters A query parameters object that is serialized and passed 59 | * directly to the Apple Music API. 60 | */ 61 | appleCurator(id: string, parameters?: QueryParameters): Promise; 62 | /** 63 | * Fetch one or more Apple curators using their identifiers. 64 | * 65 | * @param ids An array of Apple curator identifiers. 66 | * @param parameters A query parameters object that is serialized and passed 67 | * directly to the Apple Music API. 68 | */ 69 | appleCurators(ids: string[], parameters?: QueryParameters): Promise; 70 | /** 71 | * Fetch an artist using its identifier. 72 | * 73 | * @param id An artist identifier. 74 | * @param parameters A query parameters object that is serialized and passed 75 | * directly to the Apple Music API. 76 | */ 77 | artist(id: string, parameters?: QueryParameters): Promise; 78 | /** 79 | * Fetch one or more artists using their identifiers. 80 | * 81 | * @param ids An array of artist identifiers. 82 | * @param parameters A query parameters object that is serialized and passed 83 | * directly to the Apple Music API. 84 | */ 85 | artists(ids: string[], parameters?: QueryParameters): Promise; 86 | /** 87 | * Fetch one or more charts. 88 | * 89 | * @param types An array of chart types. 90 | * @param parameters A query parameters object that is serialized and passed 91 | * directly to the Apple Music API. 92 | */ 93 | charts(types: string[], parameters?: QueryParameters): Promise; 94 | /** 95 | * Fetch a curator using its identifier. 96 | * 97 | * @param id A curator identifier. 98 | * @param parameters A query parameters object that is serialized and passed 99 | * directly to the Apple Music API. 100 | */ 101 | curator(id: string, parameters?: QueryParameters): Promise; 102 | /** 103 | * Fetch one or more curators using their identifiers. 104 | * 105 | * @param ids An array of curator identifiers. 106 | * @param parameters A query parameters object that is serialized and passed 107 | * directly to the Apple Music API. 108 | */ 109 | curators(ids: string[], parameters?: QueryParameters): Promise; 110 | /** 111 | * Fetch a genre using its identifier. 112 | * 113 | * @param id An array of 114 | * @param parameters A query parameters object that is serialized and passed 115 | * directly to the Apple Music API. 116 | */ 117 | genre(id: string, parameters?: QueryParameters): Promise; 118 | /** 119 | * Fetch one or more genres using their identifiers. 120 | * 121 | * @param ids An array of genre identifiers. 122 | * @param parameters A query parameters object that is serialized and passed 123 | * directly to the Apple Music API. 124 | */ 125 | genres(ids: string[], parameters?: QueryParameters): Promise; 126 | /** 127 | * Fetch the resources in heavy rotation for the user. 128 | * 129 | * @param parameters A query parameters object that is serialized and passed 130 | * directly to the Apple Music API. 131 | */ 132 | historyHeavyRotation(parameters?: QueryParameters): Promise; 133 | /** 134 | * Fetch a music video using its identifier. 135 | * 136 | * @param id An array of video identifier. 137 | * @param parameters A query parameters object that is serialized and passed 138 | * directly to the Apple Music API. 139 | */ 140 | musicVideo(id: string, parameters?: QueryParameters): Promise; 141 | /** 142 | * Fetch one or more music videos using their identifiers. 143 | * 144 | * @param ids An array of music video identifiers. 145 | * @param parameters A query parameters object that is serialized and passed 146 | * directly to the Apple Music API. 147 | */ 148 | musicVideos(ids: string[], parameters?: QueryParameters): Promise; 149 | /** 150 | * Fetch a playlist using its identifier. 151 | * 152 | * @param id A playlist identifier. 153 | * @param parameters A query parameters object that is serialized and passed 154 | * directly to the Apple Music API. 155 | */ 156 | playlist(id: string, parameters?: QueryParameters): Promise; 157 | /** 158 | * Fetch one or more playlists using their identifiers. 159 | * 160 | * @param ids An array of playlist identifiers. 161 | * @param parameters A query parameters object that is serialized and passed 162 | * directly to the Apple Music API. 163 | */ 164 | playlists(ids: string[], parameters?: QueryParameters): Promise; 165 | /** 166 | * Fetch the recently played resources for the user. 167 | * 168 | * @param parameters A query parameters object that is serialized and passed 169 | * directly to the Apple Music API. 170 | */ 171 | recentPlayed(parameters?: QueryParameters): Promise; 172 | /** 173 | * Fetch a recommendation using its identifier. 174 | * 175 | * @param id A recommendation identifier. 176 | * @param parameters A query parameters object that is serialized and passed 177 | * directly to the Apple Music API. 178 | */ 179 | recommendation(id: string, parameters?: QueryParameters): Promise; 180 | /** 181 | * Fetch one or more recommendations using their identifiers. 182 | * 183 | * @param ids An array of recommendation identifiers. 184 | * @param parameters A query parameters object that is serialized and passed 185 | * directly to the Apple Music API. 186 | */ 187 | recommendations(ids: string[], parameters?: QueryParameters): Promise; 188 | /** 189 | * Search the catalog using a query. 190 | * 191 | * @param term The term to search. 192 | * @param parameters A query parameters object that is serialized and passed 193 | * directly to the Apple Music API. 194 | */ 195 | search(term: string, parameters?: QueryParameters): Promise; 196 | /** 197 | * Fetch the search term results for a hint. 198 | * 199 | * @param term The term to search. 200 | * @param parameters A query parameters object that is serialized and passed 201 | * directly to the Apple Music API. 202 | */ 203 | searchHints(term: string, parameters?: QueryParameters): Promise; 204 | /** 205 | * Fetch a song using its identifier. 206 | * 207 | * @param ids An array of identifier. 208 | * @param parameters A query parameters object that is serialized and passed 209 | * directly to the Apple Music API. 210 | */ 211 | song(id: string, parameters?: QueryParameters): Promise; 212 | /** 213 | * Fetch one or more songs using their identifiers. 214 | * 215 | * @param ids An array of song identifiers. 216 | * @param parameters A query parameters object that is serialized and passed 217 | * directly to the Apple Music API. 218 | */ 219 | songs(ids: string[], parameters?: QueryParameters): Promise; 220 | /** 221 | * Fetch a station using its identifier. 222 | * 223 | * @param id A station identifier. 224 | * @param parameters A query parameters object that is serialized and passed 225 | * directly to the Apple Music API. 226 | */ 227 | station(id: string, parameters?: QueryParameters): Promise; 228 | /** 229 | * Fetch one or more stations using their identifiers. 230 | * 231 | * @param ids An array of station identifiers. 232 | * @param parameters A query parameters object that is serialized and passed 233 | * directly to the Apple Music API. 234 | */ 235 | stations(ids: string[], parameters?: QueryParameters): Promise; 236 | /** 237 | * Fetch a storefront using its identifier. 238 | * 239 | * @param id A storefront identifier. 240 | * @param parameters A query parameters object that is serialized and passed 241 | * directly to the Apple Music API. 242 | */ 243 | storefront(id: string, parameters?: QueryParameters): Promise; 244 | /** 245 | * Fetch one or more storefronts using their identifiers. 246 | * 247 | * @param ids An array of storefront identifiers. 248 | * @param parameters A query parameters object that is serialized and passed 249 | * directly to the Apple Music API. 250 | */ 251 | storefronts(ids: string[], parameters?: QueryParameters): Promise; 252 | } 253 | 254 | /** 255 | * @todo add types for Apple Music API Objects 256 | * https://developer.apple.com/documentation/applemusicapi/apple_music_api_objects 257 | */ 258 | 259 | interface Resource { 260 | [key: string]: any; 261 | } 262 | 263 | type AddToLibraryParameters = any; 264 | 265 | interface QueryParameters { 266 | [key: string]: any; 267 | } 268 | 269 | /** 270 | * An object that represents artwork. 271 | */ 272 | interface Artwork { 273 | bgColor: string; 274 | height: number; 275 | width: number; 276 | textColor1: string; 277 | textColor2: string; 278 | textColor3: string; 279 | textColor4: string; 280 | url: string; 281 | } 282 | } 283 | -------------------------------------------------------------------------------- /MusicKit/MusicKit.Events.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for MusicKit JS 1.2.3 2 | // Project: https://developer.apple.com/documentation/musickitjs 3 | // Definitions by: Waseem Dahman 4 | 5 | declare namespace MusicKit { 6 | /** 7 | * A dictionary containing events for a MusicKit instance. 8 | */ 9 | const Events: { 10 | /** 11 | * A notification name indicating a change in the authorization status. 12 | */ 13 | authorizationStatusDidChange: string; 14 | /** 15 | * A notification name indicating an upcoming change in the authorization status. 16 | */ 17 | authorizationStatusWillChange: string; 18 | /** 19 | * A notification name indicating a user is eligible for a subscribe view. 20 | */ 21 | eligibleForSubscribeView: string; 22 | /** 23 | * A notification name indicating MusicKit JS is loaded. 24 | */ 25 | loaded: string; 26 | /** 27 | * A notification name indicating the player has obtained enough data for 28 | * playback to start. 29 | */ 30 | mediaCanPlay: string; 31 | /** 32 | * A notification name indicating that the currently-playing media item has 33 | * changed. 34 | */ 35 | mediaItemDidChange: string; 36 | /** 37 | * A notification name indicating the currently-playing media item is about 38 | * to change. 39 | */ 40 | mediaItemWillChange: string; 41 | /** 42 | * A notification name indicating that the player has thrown an error during 43 | * playback. 44 | */ 45 | mediaPlaybackError: string; 46 | /** 47 | * A notification name indicating the media item's metadata has finished 48 | * loading. 49 | */ 50 | metadataDidChange: string; 51 | /** 52 | * A notification indicating the playback bit rate has changed. 53 | */ 54 | playbackBitrateDidChange: string; 55 | /** 56 | * A notification name indicating the current playback duration changed. 57 | */ 58 | playbackDurationDidChange: string; 59 | /** 60 | * A notification name indicating the current playback progress changed. 61 | */ 62 | playbackProgressDidChange: string; 63 | /** 64 | * A notification indicating the playback state has changed. 65 | */ 66 | playbackStateDidChange: string; 67 | /** 68 | * A notification indicating the playback state is about to be changed. 69 | */ 70 | playbackStateWillChange: string; 71 | /** 72 | * A notification indicating that a playback target's availability has changed. 73 | */ 74 | playbackTargetAvailableDidChange: string; 75 | /** 76 | * A notification name indicating the current playback time has changed. 77 | */ 78 | playbackTimeDidChange: string; 79 | /** 80 | * A notification name indicating the player volume has changed. 81 | */ 82 | playbackVolumeDidChange: string; 83 | /** 84 | * A notification name indicating the playback has started in another context 85 | * on your domain, and the current player has stopped playback. 86 | */ 87 | primaryPlayerDidChange: string; 88 | /** 89 | * A notification name indicating that the items in the current playback 90 | * queue have changed. 91 | */ 92 | queueItemsDidChange: string; 93 | /** 94 | * A notification name indicating that the current queue position has changed. 95 | */ 96 | queuePositionDidChange: string; 97 | /** 98 | * A notification name indicating a change in the storefront country code. 99 | */ 100 | storefrontCountryCodeDidChange: string; 101 | /** 102 | * A notification name indicating that the device's inferred storefront 103 | * identifier changed. 104 | */ 105 | storefrontIdentifierDidChange: string; 106 | /** 107 | * A notification name indicating the user token changed. 108 | */ 109 | userTokenDidChange: string; 110 | }; 111 | } 112 | -------------------------------------------------------------------------------- /MusicKit/MusicKit.Library.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for MusicKit JS 1.2.3 2 | // Project: https://developer.apple.com/documentation/musickitjs 3 | // Definitions by: Waseem Dahman 4 | 5 | declare namespace MusicKit { 6 | /** 7 | * This class represents a user's Cloud Library. 8 | */ 9 | interface Library { 10 | /** 11 | * Fetch a library album using its identifier. 12 | * 13 | * @param id A library album identifier 14 | * @param parameters A query parameters object that is serialized and passed 15 | * directly to the Cloud Library API. 16 | */ 17 | album(id: string, parameters?: QueryParameters): Promise; 18 | /** 19 | * Fetch one or more library albums using their identifiers. 20 | * 21 | * @param ids An array of library album identifiers. 22 | * @param parameters A query parameters object that is serialized and passed 23 | * directly to the Cloud Library API. 24 | */ 25 | albums(ids: string[] | null, parameters?: QueryParameters): Promise; 26 | /** 27 | * Fetch a library artist using its identifier. 28 | * 29 | * @param id A library artist identifier. 30 | * @param parameters A query parameters object that is serialized and passed 31 | * directly to the Cloud Library API. 32 | */ 33 | artist(id: string, parameters?: QueryParameters): Promise; 34 | /** 35 | * Fetch one or more library artists using their identifiers. 36 | * 37 | * @param ids An array of library artist identifiers. 38 | * @param parameters A query parameters object that is serialized and passed 39 | * directly to the Cloud Library API. 40 | */ 41 | artists(ids: string[] | null, parameters?: QueryParameters): Promise; 42 | /** 43 | * Fetch a library music video using its identifier. 44 | * 45 | * @param id A library music video identifier. 46 | * @param parameters A query parameters object that is serialized and passed 47 | * directly to the Cloud Library API. 48 | */ 49 | musicVideo(id: string, parameters?: QueryParameters): Promise; 50 | /** 51 | * Fetch one or more library music videos using their identifiers. 52 | * 53 | * @param ids An array of library music video identifiers. 54 | * @param parameters A query parameters object that is serialized and passed 55 | * directly to the Cloud Library API. 56 | */ 57 | musicVideos(ids: string[] | null, parameters?: QueryParameters): Promise; 58 | /** 59 | * Fetch a library playlist using its identifier. 60 | * 61 | * @param id A library playlist identifier. 62 | * @param parameters A query parameters object that is serialized and passed 63 | * directly to the Cloud Library API. 64 | */ 65 | playlist(id: string, parameters?: QueryParameters): Promise; 66 | /** 67 | * Fetch one or more library playlists using their identifiers. 68 | * 69 | * @param ids An array of library playlist identifiers. 70 | * @param parameters A query parameters object that is serialized and passed 71 | * directly to the Cloud Library API. 72 | */ 73 | playlists(ids: string[] | null, parameters?: QueryParameters): Promise; 74 | /** 75 | * Search the library using a query. 76 | * 77 | * @param term The term to search. 78 | * @param parameters A query parameters object that is serialized and passed 79 | * directly to the Cloud Library API. 80 | */ 81 | search(term: string, parameters?: QueryParameters): Promise; 82 | /** 83 | * Fetch a library song using its identifier. 84 | * 85 | * @param id A library song identifier. 86 | * @param parameters A query parameters object that is serialized and passed 87 | * directly to the Cloud Library API. 88 | */ 89 | song(id: string, parameters?: QueryParameters): Promise; 90 | /** 91 | * Fetch one or more library songs using their identifiers. 92 | * 93 | * @param ids An array of library song identifiers. 94 | * @param parameters A query parameters object that is serialized and passed 95 | * directly to the Cloud Library API. 96 | */ 97 | songs(ids: string[] | null, parameters?: QueryParameters): Promise; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /MusicKit/MusicKit.MKError.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for MusicKit JS 1.2.3 2 | // Project: https://developer.apple.com/documentation/musickitjs 3 | // Definitions by: Waseem Dahman 4 | 5 | declare namespace MusicKit { 6 | /** 7 | * A class that describes an error that may occur when using MusicKit JS, 8 | * including server and local errors. 9 | */ 10 | class MKError extends Error { 11 | /** 12 | * The error code for this error. 13 | */ 14 | errorCode: string; 15 | /** 16 | * A description of the error that occurred. 17 | */ 18 | description?: string; 19 | /** 20 | * Error code indicating that you don't have permission to access the 21 | * endpoint, media item, or content. 22 | */ 23 | static ACCESS_DENIED: string; 24 | /** 25 | * Error code indicating the authorization was rejected. 26 | */ 27 | static AUTHORIZATION_ERROR: string; 28 | /** 29 | * Error code indicating a MusicKit JS configuration error. 30 | */ 31 | static CONFIGURATION_ERROR: string; 32 | /** 33 | * Error code indicating you don't have permission to access this content, 34 | * due to content restrictions. 35 | */ 36 | static CONTENT_RESTRICTED: string; 37 | /** 38 | * Error code indicating the parameters provided for this method are invalid. 39 | */ 40 | static INVALID_ARGUMENTS: string; 41 | /** 42 | * Error code indicating that the VM certificate could not be applied. 43 | */ 44 | static MEDIA_CERTIFICATE: string; 45 | /** 46 | * Error code indicating that the media item descriptor is invalid. 47 | */ 48 | static MEDIA_DESCRIPTOR: string; 49 | /** 50 | * Error code indicating that a DRM key could not be generated. 51 | */ 52 | static MEDIA_KEY: string; 53 | /** 54 | * Error code indicating a DRM license error. 55 | */ 56 | static MEDIA_LICENSE: string; 57 | /** 58 | * Error code indicating a media playback error. 59 | */ 60 | static MEDIA_PLAYBACK: string; 61 | /** 62 | * Error code indicating that an EME session could not be created. 63 | */ 64 | static MEDIA_SESSION: string; 65 | /** 66 | * Error code indicating a network error. 67 | */ 68 | static NETWORK_ERROR: string; 69 | /** 70 | * Error code indicating that the resource was not found. 71 | */ 72 | static NOT_FOUND: string; 73 | /** 74 | * Error code indicating that you have exceeded the Apple Music API quota. 75 | */ 76 | static QUOTA_EXCEEDED: string; 77 | static SERVER_ERROR: string; 78 | /** 79 | * Error code indicating the MusicKit service could not be reached. 80 | */ 81 | static SERVICE_UNAVAILABLE: string; 82 | /** 83 | * Error code indicating that the user's Apple Music subscription has expired. 84 | */ 85 | static SUBSCRIPTION_ERROR: string; 86 | /** 87 | * Error code indicating an unknown error. 88 | */ 89 | static UNKNOWN_ERROR: string; 90 | /** 91 | * Error code indicating that the operation is not supported. 92 | */ 93 | static UNSUPPORTED_ERROR: string; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /MusicKit/MusicKit.MediaItem.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for MusicKit JS 1.2.3 2 | // Project: https://developer.apple.com/documentation/musickitjs 3 | // Definitions by: Waseem Dahman 4 | 5 | declare namespace MusicKit { 6 | /** 7 | * This class represents a single media item. 8 | */ 9 | class MediaItem { 10 | /** 11 | * A constructor that creates a new media item from specified options. 12 | */ 13 | constructor(options?: MediaItemOptions); 14 | /** 15 | * Prepares a media item for playback. 16 | */ 17 | prepareToPlay(): Promise; 18 | /** 19 | * A string of information about the album. 20 | */ 21 | readonly albumInfo: string; 22 | /** 23 | * The title of the album. 24 | */ 25 | readonly albumName: string; 26 | /** 27 | * The artist for a media item. 28 | */ 29 | readonly artistName: string; 30 | /** 31 | * The artwork object for the media item. 32 | */ 33 | readonly artwork: Artwork; 34 | /** 35 | * The artwork image for the media item. 36 | */ 37 | readonly artworkURL: string; 38 | /** 39 | * The attributes object for the media item. 40 | */ 41 | readonly attributes: any; 42 | /** 43 | * A string containing the content rating for the media item. 44 | */ 45 | readonly contentRating: string; 46 | /** 47 | * The disc number where the media item appears. 48 | */ 49 | readonly discNumber: number; 50 | /** 51 | * The identifier for the media item. 52 | */ 53 | readonly id: string; 54 | /** 55 | * A string of common information about the media item. 56 | */ 57 | readonly info: string; 58 | /** 59 | * A Boolean value that indicates whether the item has explicit lyrics or language. 60 | */ 61 | readonly isExplicitItem: boolean; 62 | /** 63 | * A Boolean value that indicated whether the item is playable. 64 | */ 65 | readonly isPlayable: boolean; 66 | /** 67 | * A Boolean value indicating whether the media item is prepared to play. 68 | */ 69 | readonly isPreparedToPlay: boolean; 70 | /** 71 | * The ISRC (International Standard Recording Code) for a media item. 72 | */ 73 | readonly isrc: string; 74 | /** 75 | * The playback duration of the media item. 76 | */ 77 | readonly playbackDuration: number; 78 | readonly playlistArtworkURL: string; 79 | readonly playlistName: string; 80 | /** 81 | * The URL to an unencrypted preview of the media item. 82 | */ 83 | readonly previewURL: string; 84 | /** 85 | * The release date of the media item. 86 | */ 87 | readonly releaseDate?: Date; 88 | /** 89 | * The name of the media item. 90 | */ 91 | readonly title: string; 92 | /** 93 | * The number of the media item in the album's track list. 94 | */ 95 | readonly trackNumber: number; 96 | /** 97 | * The type of the media item. 98 | */ 99 | type: any; 100 | } 101 | 102 | /** 103 | * The options to use when defining a media item. 104 | */ 105 | interface MediaItemOptions { 106 | /** 107 | * The attributes for the media item. 108 | */ 109 | attributes?: any; 110 | /** 111 | * The identifier for the media item. 112 | */ 113 | id?: string; 114 | /** 115 | * The type for the media item. 116 | */ 117 | type?: any; 118 | } 119 | 120 | /** 121 | * This property describes a media item. 122 | */ 123 | type descriptor = MediaItem | string; 124 | } 125 | -------------------------------------------------------------------------------- /MusicKit/MusicKit.MusicKitInstance.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for MusicKit JS 1.2.3 2 | // Project: https://developer.apple.com/documentation/musickitjs 3 | // Definitions by: Waseem Dahman 4 | 5 | declare namespace MusicKit { 6 | /** 7 | * This object provides access to a player instance, and through the player 8 | * instance, access to control playback. 9 | */ 10 | interface MusicKitInstance { 11 | /** 12 | * An instance of the MusicKit API. 13 | */ 14 | readonly api: API; 15 | /** 16 | * An instance of the MusicKit API. 17 | */ 18 | readonly bitrate: PlaybackBitrate; 19 | /** 20 | * The developer token to identify yourself as a trusted developer and 21 | * member of the Apple Developer Program. 22 | */ 23 | readonly developerToken: string; 24 | /** 25 | * A Boolean value indicating whether the user has authenticated and 26 | * authorized the application for use. 27 | */ 28 | readonly isAuthorized: boolean; 29 | /** 30 | * A user token used to access personalized Apple Music content. 31 | */ 32 | readonly musicUserToken: string; 33 | /** 34 | * The current playback state of the music player. 35 | */ 36 | readonly playbackState: PlaybackStates; 37 | /** 38 | * A Boolean value that indicates if a playback target is available. 39 | */ 40 | readonly playbackTargetAvailable: boolean; 41 | /** 42 | * An instance of the MusicKit player. 43 | */ 44 | readonly player: Player; 45 | /** 46 | * The current storefront for the configured MusicKit instance. 47 | */ 48 | readonly storefrontId: string; 49 | /** 50 | * Add an event listener for a MusicKit instance by name. 51 | * 52 | * @param name The name of the event. 53 | * @param callback The callback function to invoke when the event occurs. 54 | */ 55 | addEventListener(name: string, callback: () => any): void; 56 | /** 57 | * No description available. 58 | */ 59 | addToLibrary(id: any, type: any): Promise; 60 | /** 61 | * Returns a promise containing a music user token when a user has 62 | * authenticated and authorized the app. 63 | */ 64 | authorize(): Promise; 65 | /** 66 | * Begins playing the media item at the specified index in the queue. 67 | * 68 | * @param index The queue index to begin playing media. 69 | */ 70 | changeToMediaAtIndex(index: number): Promise; 71 | /** 72 | * Pauses playback of the media player. 73 | */ 74 | pause(): void; 75 | /** 76 | * Begins playback of the current media item. 77 | */ 78 | play(): Promise; 79 | /** 80 | * No description available. 81 | */ 82 | playLater(options: SetQueueOptions): Promise; 83 | /** 84 | * No description available. 85 | */ 86 | playNext(options: SetQueueOptions): Promise; 87 | /** 88 | * Removes an event listener for a MusicKit instance by name. 89 | * 90 | * @param name The name of the event. 91 | * @param callback The callback function to remove. 92 | */ 93 | removeEventListener(name: string, callback: () => any): void; 94 | /** 95 | * Sets the playback point to a specified time. 96 | * 97 | * @param time The time to set as the playback point. 98 | */ 99 | seekToTime(time: number): Promise; 100 | /** 101 | * Sets a music player's playback queue using queue options. 102 | * 103 | * @param options The option used to set the playback queue. 104 | */ 105 | setQueue(options: SetQueueOptions): Promise; 106 | /** 107 | * Starts playback of the next media item in the playback queue. 108 | */ 109 | skipToNextItem(): Promise; 110 | /** 111 | * Starts playback of the previous media item in the playback queue. 112 | */ 113 | skipToPreviousItem(): Promise; 114 | /** 115 | * Stops playback of the media player. 116 | */ 117 | stop(): void; 118 | /** 119 | * Unauthorizes the app for the current user. 120 | */ 121 | unauthorize(): Promise; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /MusicKit/MusicKit.Player.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for MusicKit JS 1.2.3 2 | // Project: https://developer.apple.com/documentation/musickitjs 3 | // Definitions by: Waseem Dahman 4 | 5 | declare namespace MusicKit { 6 | /** 7 | * A media player that represents the media player for a MusicKit instance. 8 | */ 9 | interface Player { 10 | /** 11 | * The current bit rate of the music player. 12 | */ 13 | readonly bitrate: number; 14 | /** 15 | * The music player has EME loaded. 16 | */ 17 | readonly canSupportDRM: boolean; 18 | /** 19 | * The current playback duration. 20 | */ 21 | readonly currentPlaybackDuration: number; 22 | /** 23 | * The current playback progress. 24 | */ 25 | readonly currentPlaybackProgress: number; 26 | /** 27 | * The current position of the playhead. 28 | */ 29 | readonly currentPlaybackTime: number; 30 | /** 31 | * No description available. 32 | */ 33 | readonly currentPlaybackTimeRemaining: number; 34 | /** 35 | * The current playback duration in hours and minutes. 36 | */ 37 | readonly formattedCurrentPlaybackDuration: FormattedPlaybackDuration; 38 | /** 39 | * A Boolean value indicating whether the player is currently playing. 40 | */ 41 | readonly isPlaying: boolean; 42 | /** 43 | * The currently-playing media item, or the media item, within an queue, 44 | * that you have designated to begin playback. 45 | */ 46 | readonly nowPlayingItem: MediaItem; 47 | /** 48 | * The index of the now playing item in the current playback queue. 49 | */ 50 | readonly nowPlayingItemIndex?: number; 51 | /** 52 | * The current playback rate for the player. 53 | */ 54 | readonly playbackRate: number; 55 | /** 56 | * The current playback state of the music player. 57 | */ 58 | readonly playbackState: PlaybackStates; 59 | /** 60 | * A Boolean value that indicates whether a playback target is available. 61 | */ 62 | readonly playbackTargetAvailable?: boolean; 63 | /** 64 | * The current playback queue of the music player. 65 | */ 66 | readonly queue: Queue; 67 | /** 68 | * The current repeat mode of the music player. 69 | */ 70 | repeatMode: PlayerRepeatMode; 71 | /** 72 | * The current shuffle mode of the music player. 73 | */ 74 | shuffleMode: PlayerShuffleMode; 75 | /** 76 | * A number indicating the current volume of the music player. 77 | */ 78 | volume: number; 79 | /** 80 | * Adds an event listener as a callback for an event name. 81 | * 82 | * @param name The name of the event. 83 | * @param callback The callback function to invoke when the event occurs. 84 | */ 85 | addEventListener(name: string, callback: () => any): void; 86 | /** 87 | * Begins playing the media item at the specified index in the queue immediately. 88 | * 89 | * @param The queue index to begin playing media. 90 | */ 91 | changeToMediaAtIndex(index: number): Promise; 92 | /** 93 | * Begins playing the media item in the queue immediately. 94 | * 95 | * @param descriptor descriptor can be a MusicKit.MediaItem instance or a 96 | * string identifier. 97 | */ 98 | changeToMediaItem(descriptor: descriptor): Promise; 99 | /** 100 | * Sets the volume to 0. 101 | */ 102 | mute(): void; 103 | /** 104 | * Pauses playback of the current item. 105 | */ 106 | pause(): void; 107 | /** 108 | * Initiates playback of the current item. 109 | */ 110 | play(): Promise; 111 | /** 112 | * Prepares a music player for playback. 113 | * 114 | * @param descriptor descriptor can be a MusicKit.MediaItem instance or a 115 | * string identifier. 116 | */ 117 | prepareToPlay(descriptor: descriptor): Promise; 118 | /** 119 | * No description available. 120 | * 121 | * @param name The name of the event. 122 | * @param callback The callback function to remove. 123 | */ 124 | removeEventListener(name: string, callback: () => any): void; 125 | /** 126 | * Sets the playback point to a specified time. 127 | * 128 | * @param time The time to set as the playback point. 129 | */ 130 | seekToTime(time: number): Promise; 131 | /** 132 | * Displays the playback target picker if a playback target is available. 133 | */ 134 | showPlaybackTargetPicker(): void; 135 | /** 136 | * Starts playback of the next media item in the playback queue. 137 | */ 138 | skipToNextItem(): Promise; 139 | /** 140 | * Starts playback of the previous media item in the playback queue. 141 | */ 142 | skipToPreviousItem(): Promise; 143 | /** 144 | * Stops the currently playing media item. 145 | */ 146 | stop(): void; 147 | } 148 | 149 | /** 150 | * The playback states of the music player. 151 | */ 152 | enum PlaybackStates { 153 | none, 154 | loading, 155 | playing, 156 | paused, 157 | stopped, 158 | ended, 159 | seeking, 160 | waiting, 161 | stalled, 162 | completed, 163 | } 164 | 165 | /** 166 | * The playback bit rate of the music player. 167 | */ 168 | enum PlaybackBitrate { 169 | HIGH = 256, 170 | STANDARD = 64, 171 | } 172 | 173 | // enum is not exposed via the MusicKit namespace 174 | type PlayerRepeatMode = 0 | 1 | 2; 175 | 176 | // enum is not exposed via the MusicKit namespace 177 | type PlayerShuffleMode = 0 | 1; 178 | 179 | type MediaItemPosition = number; 180 | } 181 | -------------------------------------------------------------------------------- /MusicKit/MusicKit.Queue.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for MusicKit JS 1.2.3 2 | // Project: https://developer.apple.com/documentation/musickitjs 3 | // Definitions by: Waseem Dahman 4 | 5 | declare namespace MusicKit { 6 | /** 7 | * An array of media items to be played. 8 | */ 9 | interface Queue { 10 | /** 11 | * A Boolean value indicating whether the queue has no items. 12 | */ 13 | readonly isEmpty: boolean; 14 | /** 15 | * An array of all the media items in the queue. 16 | */ 17 | readonly items: MediaItem[]; 18 | /** 19 | * The number of items in the queue. 20 | */ 21 | readonly length: number; 22 | /** 23 | * The next playable media item in the queue. 24 | */ 25 | readonly nextPlayableItem?: MediaItem; 26 | /** 27 | * The current queue position. 28 | */ 29 | readonly position: number; 30 | /** 31 | * The previous playable media item in the queue. 32 | */ 33 | readonly previousPlayableItem?: MediaItem; 34 | 35 | /** 36 | * Add an event listener for a MusicKit queue by name. 37 | * 38 | * @param name The name of the event. 39 | * @param callback The callback function to remove. 40 | */ 41 | addEventListener(name: string, callback: () => any): void; 42 | /** 43 | * Inserts the media items defined by the queue descriptor after the last 44 | * media item in the current queue. 45 | */ 46 | append(descriptor: descriptor): void; 47 | /** 48 | * Returns the index in the playback queue for a media item descriptor. 49 | * 50 | * @param descriptor A descriptor can be an instance of the MusicKit.MediaItem 51 | * class, or a string identifier. 52 | */ 53 | indexForItem(descriptor: descriptor): number; 54 | /** 55 | * Returns the media item located in the indicated array index. 56 | */ 57 | item(index: number): MediaItem | null | undefined; 58 | /** 59 | * Inserts the media items defined by the queue descriptor into the current 60 | * queue immediately after the currently playing media item. 61 | */ 62 | prepend(descriptor: any): void; 63 | /** 64 | * Removes an event listener for a MusicKit queue by name. 65 | * 66 | * @param name The name of the event. 67 | * @param callback The callback function to remove. 68 | */ 69 | removeEventListener(name: string, callback: () => any): void; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /MusicKit/MusicKit.SetQueueOptions.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for MusicKit JS 1.2.3 2 | // Project: https://developer.apple.com/documentation/musickitjs 3 | // Definitions by: Waseem Dahman 4 | 5 | declare namespace MusicKit { 6 | /** 7 | * The options to use when setting a music player's playback queue. 8 | */ 9 | interface SetQueueOptions { 10 | /** 11 | * The catalog album used to set a music player's playback queue. 12 | */ 13 | album?: string; 14 | /** 15 | * The media items used to set a music player's playback queue. 16 | */ 17 | items: descriptor[]; 18 | /** 19 | * The parameters used to set a music player's playback queue. 20 | */ 21 | parameters?: QueryParameters; 22 | /** 23 | * The playlist used to set a music player's playback queue. 24 | */ 25 | playlist?: string; 26 | /** 27 | * The song used to set a music player's playback queue. 28 | */ 29 | song?: string; 30 | /** 31 | * The songs used to set a music player's playback queue. 32 | */ 33 | songs?: string[]; 34 | /** 35 | * The start position for a set playback queue. 36 | */ 37 | startPosition?: number; 38 | /** 39 | * A content URL used to set a music player's playback queue. 40 | */ 41 | url?: string; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /MusicKit/MusicKit.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for MusicKit JS 1.2.3 2 | // Project: https://developer.apple.com/documentation/musickitjs 3 | // Definitions by: Waseem Dahman 4 | 5 | /** 6 | * Use the MusicKit namespace to configure MusicKit JS and to access app 7 | * instances, control music playback, and fetch data from the Apple Music API. 8 | */ 9 | declare namespace MusicKit { 10 | /** 11 | * Configure a MusicKit instance. 12 | */ 13 | function configure(configuration: Configuration): MusicKitInstance; 14 | /** 15 | * Returns the configured MusicKit instance. 16 | */ 17 | function getInstance(): MusicKitInstance; 18 | /** 19 | * Returns a formatted artwork URL. 20 | * 21 | * @param artwork An artwork resource object. 22 | * @param height The desired artwork height. 23 | * @param width the desired artwork width. 24 | */ 25 | function formatArtworkURL(artwork: Artwork, height: number, width: number): string; 26 | /** 27 | * Returns an object with milliseconds formatted into hours and minutes. 28 | */ 29 | function formattedMilliseconds(milliseconds: number): FormattedPlaybackDuration; 30 | /** 31 | * Returns an object with seconds formatted into hours and minutes. 32 | */ 33 | function formattedSeconds(seconds: number): FormattedPlaybackDuration; 34 | /** 35 | * Generates Apple Music web player markup. 36 | * 37 | * @param url The iTunes URL for the Apple Music content. 38 | * @param options The object containing the height and width of the player. 39 | */ 40 | function generateEmbedCode(url: string, options: EmbedOptions): string; 41 | 42 | function formatMediaTime(seconds: number, separator: string): string; 43 | 44 | const errors: MKError[]; 45 | 46 | const version: string; 47 | 48 | /** 49 | * A dictionary of configuration options for the MusicKit instance. 50 | */ 51 | interface Configuration { 52 | /** 53 | * The version of your app. 54 | */ 55 | app?: AppConfiguration; 56 | /** 57 | * This property indicates whether you have explicitly enabled or disabled 58 | * declarative markup. 59 | */ 60 | declarativeMarkup?: boolean; 61 | /** 62 | * The developer token to identify yourself as a trusted developer and 63 | * member of the Apple Developer Program. 64 | */ 65 | developerToken?: string; 66 | /** 67 | * The current storefront for this MusicKit configuration. 68 | */ 69 | storefrontId?: string; 70 | /** 71 | * The playback bit rate of the music player. 72 | */ 73 | bitrate?: PlaybackBitrate; 74 | } 75 | 76 | /** 77 | * A configuration for an app. 78 | */ 79 | interface AppConfiguration { 80 | /** 81 | * The build number of your app. 82 | */ 83 | build?: string; 84 | /** 85 | * A URL for your app icon. 86 | */ 87 | icon?: string; 88 | /** 89 | * The name of your app. 90 | */ 91 | name?: string; 92 | /** 93 | * The version of your app. 94 | */ 95 | version?: string; 96 | } 97 | 98 | interface FormattedPlaybackDuration { 99 | hours: number; 100 | minutes: number; 101 | } 102 | 103 | interface EmbedOptions { 104 | height: number | string; 105 | width: number | string; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /MusicKit/index.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for MusicKit JS 1.2.3 2 | // Project: https://developer.apple.com/documentation/musickitjs 3 | // Definitions by: Waseem Dahman 4 | 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | /// 11 | /// 12 | /// 13 | /// 14 | /// 15 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | MusicKit and the Apple logo are trademarks of Apple Inc., registered in the U.S. and other countries. 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/wsmd/musickit-typescript.svg?branch=master)](https://travis-ci.org/wsmd/musickit-typescript) 2 | [![License](https://img.shields.io/github/license/wsmd/musickit-typescript.svg)](https://github.com/wsmd/musickit-typescript/blob/master/LICENSE) 3 | [![Current Release](https://img.shields.io/npm/v/musickit-typescript.svg)](https://www.npmjs.com/package/musickit-typescript) 4 | 5 | # musickit-typescript 6 | 7 | TypeScript type definitions for [MusicKit JS](https://developer.apple.com/documentation/musickitjs). 8 | 9 | ## Installation 10 | 11 | First, install the types in your project: 12 | 13 | ```sh 14 | # using npm 15 | npm install --save-dev musickit-typescript 16 | 17 | # using yarn 18 | yarn add --dev musickit-typescript 19 | ``` 20 | 21 | Then, add `node_modules/musickit-typescript` to your `tsconifg.json` file like so: 22 | 23 | 24 | ```json 25 | { 26 | "compilerOptions": { 27 | "typeRoots": [ 28 | "node_modules/musickit-typescript", 29 | "node_modules/@types" 30 | ] 31 | } 32 | } 33 | ``` 34 | 35 | This will enable the TypeScript compiler to find and use this typing since it is not installed under `node_modules/@types`. 36 | 37 | By default the compiler only looks at `node_modules/@types` for type declarations. If `typeRoots` does not already exist in the `tsconfig.json` file, make sure to include `node_modules/@types` as well. 38 | 39 | ## Legal 40 | 41 | MusicKit and the Apple logo are trademarks of Apple Inc., registered in the U.S. and other countries. 42 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "musickit-typescript", 3 | "version": "1.2.4", 4 | "description": "Typescript type definitions for MusicKit", 5 | "repository": "wsmd/musickit-typescript", 6 | "types": "./MusicKit/index.d.ts", 7 | "bugs": { 8 | "url": "https://github.com/wsmd/musickit-typescript/issues" 9 | }, 10 | "scripts": { 11 | "lint": "tslint **/*.d.ts", 12 | "test": "npm run typecheck && npm run lint", 13 | "typecheck": "tsc --noEmit", 14 | "typecheck:dev": "tsc --noEmit --watch", 15 | "prepack": "npm run test" 16 | }, 17 | "author": "Waseem Dahman ", 18 | "license": "MIT", 19 | "files": [ 20 | "MusicKit", 21 | "NOTICE" 22 | ], 23 | "keywords": [ 24 | "Apple", 25 | "apple-music", 26 | "MusicKit.d.ts", 27 | "MusicKit", 28 | "types", 29 | "typescript", 30 | "typings" 31 | ], 32 | "devDependencies": { 33 | "tslint": "^5.12.1", 34 | "typescript": "^3.2.2" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /scripts/update-version: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for file in `find . -regex '\./.*\.d\.ts' -not -path './node_modules/*'`; do 4 | sed -i '' -E "1s/([0-9]{1,}\.?){1,}/$1/" $file 5 | echo "updated: $file" 6 | done 7 | 8 | npm version $1 --no-git-tag-version --allow-same-version > /dev/null 9 | echo "updated: package.json" 10 | -------------------------------------------------------------------------------- /test/MusicKit-test.ts: -------------------------------------------------------------------------------- 1 | let music: MusicKit.MusicKitInstance; 2 | 3 | const appConfig: MusicKit.AppConfiguration = { 4 | build: '1234', 5 | icon: 'icon.png', 6 | name: 'app-name', 7 | version: '1.0.0', 8 | }; 9 | 10 | music = MusicKit.configure({ 11 | app: appConfig, 12 | developerToken: 'abc123', 13 | storefrontId: '123', 14 | declarativeMarkup: true, 15 | bitrate: MusicKit.PlaybackBitrate.HIGH, 16 | }); 17 | 18 | let instance: MusicKit.MusicKitInstance; 19 | instance = MusicKit.getInstance(); 20 | 21 | music.bitrate.toString(); 22 | music.developerToken.charCodeAt(0); 23 | music.storefrontId.charCodeAt(0); 24 | music.isAuthorized === true; 25 | music.musicUserToken.charCodeAt(0); 26 | music.playbackTargetAvailable === false; 27 | 28 | const api: MusicKit.API = music.api; 29 | const playbackState: MusicKit.PlaybackStates = music.playbackState; 30 | const player: MusicKit.Player = music.player; 31 | 32 | music.addEventListener(MusicKit.Events.mediaItemDidChange, () => {}); 33 | music.addToLibrary(1, 'type').then(() => {}); 34 | music.authorize().then(token => token.charCodeAt(0)); 35 | music.changeToMediaAtIndex(1).then(position => position > 1); 36 | music.play().then(position => position > 1); 37 | 38 | music.removeEventListener(MusicKit.Events.mediaItemDidChange, () => {}); 39 | music.seekToTime(12345).then(() => {}); 40 | music.skipToNextItem().then(position => position > 1); 41 | music.skipToPreviousItem().then(position => position > 1); 42 | music.stop(); 43 | music.unauthorize().then(() => {}); 44 | 45 | player.bitrate.toString(); 46 | player.canSupportDRM === true; 47 | player.currentPlaybackDuration > 10; 48 | player.currentPlaybackProgress < 1; 49 | player.currentPlaybackTime > 10; 50 | player.currentPlaybackTimeRemaining > 30; 51 | player.formattedCurrentPlaybackDuration.hours < 1; 52 | player.formattedCurrentPlaybackDuration.minutes > 3; 53 | player.isPlaying === true; 54 | player.nowPlayingItemIndex && player.nowPlayingItemIndex > 1; 55 | player.playbackRate > 1; 56 | player.playbackTargetAvailable === true; 57 | const playerQueue: MusicKit.Queue = player.queue; 58 | player.repeatMode > 1; 59 | player.repeatMode = 2; 60 | player.shuffleMode < 1; 61 | player.shuffleMode = 1; 62 | player.volume < 1; 63 | player.volume = 0; 64 | 65 | let nowPlayingItem: MusicKit.MediaItem; 66 | nowPlayingItem = player.nowPlayingItem; 67 | 68 | player.addEventListener(MusicKit.Events.playbackTimeDidChange, () => {}); 69 | player.removeEventListener(MusicKit.Events.playbackProgressDidChange, () => {}); 70 | player.changeToMediaAtIndex(1); 71 | player.changeToMediaItem('descriptor').then(position => position > 1); 72 | player.mute(); 73 | player.pause(); 74 | player.play(); 75 | player.stop(); 76 | player.prepareToPlay('descriptor'); 77 | player.seekToTime(1); 78 | player.showPlaybackTargetPicker(); 79 | player.skipToNextItem().then(position => position > 1); 80 | player.skipToPreviousItem().then(position => position > 1); 81 | 82 | let state: number = MusicKit.PlaybackStates.none; 83 | state = MusicKit.PlaybackStates.loading; 84 | state = MusicKit.PlaybackStates.playing; 85 | state = MusicKit.PlaybackStates.paused; 86 | state = MusicKit.PlaybackStates.stopped; 87 | state = MusicKit.PlaybackStates.ended; 88 | state = MusicKit.PlaybackStates.seeking; 89 | state = MusicKit.PlaybackStates.waiting; 90 | state = MusicKit.PlaybackStates.stalled; 91 | state = MusicKit.PlaybackStates.completed; 92 | 93 | // API 94 | 95 | api.activities(['ID']).then(); 96 | api.activity('ID').then(); 97 | 98 | api.addToLibrary(['ID']); 99 | 100 | api.album('ID').then(); 101 | api.albums(['ID']).then(); 102 | 103 | api.appleCurator('ID').then(); 104 | api.appleCurators(['ID']).then(); 105 | 106 | api.artist('ID').then(); 107 | api.artists(['ID']).then(); 108 | 109 | api.charts(['ID']).then(); 110 | 111 | api.curator('ID').then(); 112 | api.curators(['ID']).then(); 113 | 114 | api.genre('ID').then(); 115 | api.genres(['ID']).then(); 116 | 117 | api.historyHeavyRotation(['ID']).then(); 118 | 119 | api.musicVideo('ID').then(); 120 | api.musicVideos(['ID']).then(); 121 | 122 | api.playlist('ID').then(); 123 | api.playlists(['ID']).then(); 124 | 125 | api.recentPlayed(['ID']).then(); 126 | 127 | api.recommendation('ID').then(); 128 | api.recommendations(['ID']).then(); 129 | 130 | api.search('ID').then(); 131 | api.searchHints('ID').then(); 132 | 133 | api.song('ID').then(); 134 | api.songs(['ID']).then(); 135 | 136 | api.station('ID').then(); 137 | api.stations(['ID']).then(); 138 | 139 | api.storefront('ID').then(); 140 | api.storefronts(['ID']).then(); 141 | 142 | // Library 143 | 144 | let library: MusicKit.Library = api.library; 145 | 146 | library.album('ID').then(); 147 | library.albums(['ID']).then(); 148 | library.albums(null).then(); 149 | 150 | library.artist('ID').then(); 151 | library.artists(['ID']).then(); 152 | library.artists(null).then(); 153 | 154 | library.musicVideo('ID').then(); 155 | library.musicVideos(['ID']).then(); 156 | library.musicVideos(null).then(); 157 | 158 | library.playlist('ID').then(); 159 | library.playlists(['ID']).then(); 160 | library.playlists(null).then(); 161 | 162 | library.search('term').then(); 163 | 164 | library.song('ID').then(); 165 | library.songs(['ID']).then(); 166 | library.songs(null).then(); 167 | 168 | // MediaItem 169 | 170 | const item: MusicKit.MediaItem = new MusicKit.MediaItem({ 171 | attributes: {}, 172 | type: 'playlist', 173 | }); 174 | 175 | item.prepareToPlay().then(); 176 | item.albumInfo; 177 | item.albumName; 178 | item.artistName; 179 | item.artwork; 180 | item.artworkURL; 181 | item.attributes; 182 | item.contentRating; 183 | item.discNumber; 184 | item.id; 185 | item.info; 186 | item.isExplicitItem; 187 | item.isPlayable; 188 | item.isPreparedToPlay; 189 | item.isrc; 190 | item.playbackDuration; 191 | item.playlistArtworkURL; 192 | item.playlistName; 193 | item.previewURL; 194 | item.releaseDate; 195 | item.title; 196 | item.trackNumber; 197 | item.type; 198 | 199 | // Queue 200 | 201 | const items = [new MusicKit.MediaItem()]; 202 | music.playLater({ items }).then(); 203 | music.playNext({ items }); 204 | music.setQueue({ items, startPosition: 0 }).then(queue => { 205 | if (queue.nextPlayableItem) { 206 | console.log(queue.nextPlayableItem.title); 207 | } 208 | if (queue.previousPlayableItem) { 209 | console.log(queue.previousPlayableItem); 210 | } 211 | }); 212 | 213 | const queue: MusicKit.Queue = music.player.queue; 214 | queue.isEmpty === false; 215 | queue.items.map(item => item.title); 216 | queue.length > 1; 217 | queue.position > 0; 218 | queue.addEventListener(MusicKit.Events.queueItemsDidChange, () => {}); 219 | queue.removeEventListener(MusicKit.Events.queuePositionDidChange, () => {}); 220 | 221 | queue.append(item); 222 | queue.prepend(item); 223 | queue.indexForItem(item) > 0; 224 | 225 | const firstItem = queue.item(0); 226 | if (firstItem) { 227 | console.log(firstItem.title); 228 | } 229 | 230 | // Errors 231 | 232 | function errorMessage(error: MusicKit.MKError) { 233 | const messages = { 234 | [MusicKit.MKError.ACCESS_DENIED]: "you don't have permission", 235 | [MusicKit.MKError.AUTHORIZATION_ERROR]: 'authorization was rejected', 236 | [MusicKit.MKError.CONFIGURATION_ERROR]: 'configuration error', 237 | [MusicKit.MKError.CONTENT_RESTRICTED]: 'content is restricted', 238 | [MusicKit.MKError.INVALID_ARGUMENTS]: 'parameters provided are invalid', 239 | [MusicKit.MKError.MEDIA_CERTIFICATE]: 'VM certificate could not be applied', 240 | [MusicKit.MKError.MEDIA_DESCRIPTOR]: 'the media item descriptor is invalid', 241 | [MusicKit.MKError.MEDIA_KEY]: 'DRM key could not be generated', 242 | [MusicKit.MKError.MEDIA_LICENSE]: ' DRM license error', 243 | [MusicKit.MKError.MEDIA_PLAYBACK]: 'media playback error', 244 | [MusicKit.MKError.MEDIA_SESSION]: 'EME session could not be created', 245 | [MusicKit.MKError.NETWORK_ERROR]: 'network error', 246 | [MusicKit.MKError.NOT_FOUND]: 'resource was not found', 247 | [MusicKit.MKError.QUOTA_EXCEEDED]: ' exceeded the api quota', 248 | [MusicKit.MKError.SERVER_ERROR]: 'server error', 249 | [MusicKit.MKError.SERVICE_UNAVAILABLE]: 'service could not be reached', 250 | [MusicKit.MKError.SUBSCRIPTION_ERROR]: 'subscription has expired', 251 | [MusicKit.MKError.UNKNOWN_ERROR]: 'unknown error', 252 | [MusicKit.MKError.UNSUPPORTED_ERROR]: 'operation is not supported', 253 | }; 254 | return messages[error.errorCode] || 'something went wrong!'; 255 | } 256 | 257 | async function getArtists() { 258 | try { 259 | await MusicKit.getInstance().api.library.artist(''); 260 | } catch (err) { 261 | console.log(errorMessage(err)); 262 | } 263 | } 264 | 265 | MusicKit.errors.map(error => error.errorCode); 266 | 267 | // Utilities 268 | 269 | MusicKit.formatArtworkURL(player.nowPlayingItem.artwork, 300, 300); 270 | MusicKit.formatArtworkURL(item.attributes.artwork, 300, 300); 271 | MusicKit.formatArtworkURL({ url: 'path/to/artwork' } as MusicKit.Artwork, 300, 300); 272 | 273 | const { hours, minutes } = MusicKit.formattedMilliseconds(3000); 274 | 275 | MusicKit.generateEmbedCode('path/to/content', { width: '400px', height: '400px' }); 276 | 277 | const version: string = MusicKit.version; 278 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["es6", "dom"], 4 | "module": "umd", 5 | "noEmit": true, 6 | "noImplicitAny": true, 7 | "strictNullChecks": true, 8 | "target": "es6", 9 | "types": [] 10 | }, 11 | "files": ["MusicKit/index.d.ts", "test/MusicKit-test.ts"] 12 | } 13 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:latest", 3 | "linterOptions": { 4 | "exclude": ["test/**", "node_modules/**"] 5 | }, 6 | "rules": { 7 | "interface-name": [true, "never-prefix"], 8 | "max-classes-per-file": false, 9 | "max-line-length": [true, 100], 10 | "member-access": [true, "no-public"], 11 | "member-ordering": false, 12 | "no-namespace": false, 13 | "no-reference": false, 14 | "quotemark": [true, "single"] 15 | } 16 | } 17 | --------------------------------------------------------------------------------