MusicKit JS

RSS for tag

Add an Apple Music player to your web app using MusicKit JS.

MusicKit JS Documentation

Posts under MusicKit JS tag

30 Posts
Sort by:
Post not yet marked as solved
4 Replies
2.5k Views
I want to use Apple Music using MusicKit. I've created MusicKit identifier and private key by following all the steps mentioned here: https://help.apple.com/developer-account/#/devce5522674 I have my Team ID, the Music key ID and the private key (.p8 file) with me. I tried to generate the required JWT token by using many scripts that were mentioned in similar questions asked here, but none of them have worked so far. When I try to authenticate, I'm getting an error ERROR_FAILED_TO_VERIFY_JWT. Ref: Codes I've tried to generate the JWT token from: Thread 130168 - https://developer.apple.com/forums/thread/130168 A nice and simple blog by Lee Martin [Blog - Creating an Apple Music API Token] Thread 79074 - https://developer.apple.com/forums/thread/79074 Many other links But sadly, none of them worked and I had to post this question. I have tried the sample Android app: https://developer.apple.com/download/more/?=Android%20MusicKit After authentication, the page goes on with an infinite loader, which I believe must be because of the same error ERROR_FAILED_TO_VERIFY_JWT Also tried with this HTML page: <html> <head> <meta name="apple-music-developer-token" content="the-JWT-token-generated-using-the-reference-links"> <meta name="apple-music-app-name" content="My App Name"> <meta name="apple-music-app-build" content="1978.4.1"> </head> <body> <button id="apple-music-authorize"></button> <button id="apple-music-unauthorize"></button> </body> <script src="link-to-musickit.js"></script> <script> let music = MusicKit.getInstance(); &#9;&#9;music.player.play(); &#9;&#9;music.authorize().then(function() { &#9;&#9;&#9;&#9;music.player.play(); &#9;&#9;}); &#9;&#9;music.authorize().then(function() { &#9;&#9;&#9;&#9; music.api.library.albums.then(function(cloudAlbums) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;// user's cloudAlbums &#9;&#9;&#9;&#9;}); &#9;&#9;}); </script> </html>
Posted
by
Post not yet marked as solved
1 Replies
1.6k Views
Hello everyone! I am using the web version of the Apple Music Kit API, and similar to how Apple is able to produce a user's year in rewind playlist showing the most played artists/songs from a year, I am trying to replicate it for either a year or all time. I have been searching the internet for days trying to figure it out, but I've been completely stuck. I am able to make the following HTTP request successfully. GET https://api.music.apple.com/v1/me/library/songs/ which returns back the user's library of songs, but I haven't figured out how to get the play count. I have tried adding a query like such ?extend=playCount, but that doesn't work. I can see here that the Swift Music Kit API is able to extend a play count property, but I haven't been able to figure it out for Web. Ideally, I am looking for an endpoint that just shows a user's top artist/tracks similar to Spotify, however, whenever I try to use the heavy in rotation endpoint here, it always returns an empty array. The way that I have described is the long-roundabout way where I'll have to fetch each individual song and sort by playCount. But if anyone happens to know how I can do either of the options I've described, it will be truly appreciated ! I've seen other forums posts from years ago, but hopefully there's been a discovered way. Thank you!
Posted
by
Post not yet marked as solved
3 Replies
1.9k Views
I'm making a request to get 10 artists with their top songs at once, but for some artists it will always fail with a 504. The response is also in HTML which leads to a decoding error. This is my code var request = MusicCatalogResourceRequest<Artist>(matching: \.id, memberOf: ids) request.properties = properties let response = try await request.response() where ids is MusicItemId. Below I have an input which will always fail 100% of the time, even when retried. 10 elements  - 0 : "51639"  - 1 : "331584"  - 2 : "120199"  - 3 : "45058"  - 4 : "284786497"  - 5 : "44984"  - 6 : "37299"  - 7 : "518462"  - 8 : "39525"  - 9 : "73568" Example response: [DataRequesting] Failed to parse body of response with status code Unknown (504):  <!DOCTYPE html> <html lang="en"> <head>   <style>     body {       font-family: "Helvetica Neue", "HelveticaNeue", Helvetica, Arial, sans-serif;       font-size: 15px;       font-weight: 200;       line-height: 20px;       color: #4c4c4c;       text-align: center;     }     .section {       margin-top: 50px;     }   </style> </head> <body> <div class="section">   <h1>&#63743;</h1>   <h3>Gateway Timeout</h3>   <p>Correlation Key: WFRI6Q5HXAUJYXGNRKQ6YTBYIM</p> </div> </body> </html> I have also tried batching these into 2 requests of 5 artists instead of 1 request of 10 artists which still fails. However, I do have sets of 10 artists that work fine. Anyone know why?
Posted
by
Post not yet marked as solved
0 Replies
545 Views
Hello everyone, I'm currently working on some projects in React that involve using MusicKit on the web. However, I've been having some trouble finding a package that works with React. I've noticed that there's a beta version of MusicKit for web available, but I'm not sure if Apple has released an npm package for it yet. If there isn't an npm package available, is it still possible to use MusicKit on the web using just HTML and JavaScript? I'd appreciate any guidance or advice on how to get started with this. Thank you in advance for your help! Best regards.
Posted
by
Post not yet marked as solved
0 Replies
518 Views
There are a couple of tracks that recently are throwing an net::ERR_FILE_NOT_FOUND error in console. All other songs are playing music just fine. One ID in question: 1685732269
Posted
by
Post not yet marked as solved
0 Replies
788 Views
Hi, We are a funded startup developing a music festival and concert application that integrates with Apple Music. Two big features the API is missing are PUT and DELETE endpoints for tracks on a playlist. Both of these would drastically enhance the user experience on third-party apps that leverage Apple Music, specifically for editing and curating playlists. We have also noticed many errors returned as 403 when we have literally just signed in with a brand new token. We have confirmed on our end that the token is valid, fresh and can be used through other clients. As well, Apple's MusicKitJS SDK could use a bit of work. We were able to unminify and work around these issues; most of them were addressed with a simple try/catch and retry routine. We love the Apple Music API and SDK, and in general found it super easy to integrate with, setup and use. We also firmly believe Apple puts out superior products to other technology firms in the same industry. It was disappointing to see the API and SDK for Apple Music falling behind compared to other music providers who offer similar API's. We really hope Apple improves and enhances these offerings in the future. Also just wanted to give a shotout and thanks to all of the devs who make these services accessible and the integration possible. We wouldn't be here without you, and didn't want this post to come off as a rant just more of a friendly "nudge."
Posted
by
Post not yet marked as solved
0 Replies
844 Views
[Ticket on Feedback Assistant FB12353357] Hi there, We’re experiencing issues playing explicit songs using MusicKitJS for the Web (tested on both stable v1 and beta v3). Upon calling the SDK’s “play()” function, the following error gets logged in the console “CONTENT_RESTRICTED: Content restricted” and playback doesn’t begin. The Storefront we’ve tested in is “it”, but very likely all of them are impacted with the issue, here’s a few Adam IDs of affected tracks: 1681182396, 1683117248, 1669607876. A quick check with the REST APIs reveals indeed that the relevant thing all 3 of them have in common is "contentRating" being "explicit”. The bug isn’t however easy or predictable to replicate because it seems that it can be somewhat solved by fiddling with both the “Screen Time” restrictions settings within an iOS/iPadOS device (of course logged in with the same Apple account), as well as with the “Parental Controls” dashboard located in the Web version of the Apple Music’s settings page. We’re still not 100% sure what exactly “triggers” the fix, but both mentioned dashboards above are essential in attempting to solve it by trial and error. Specifically: in the “Parental Controls” dashboard what helps is actually turning ON the restrictions with the toggle, and then easing them up the most by specifically setting the less restricted available option in all 3 dropdown menus (pretty baffling); in the “Screen time” dashboard what helps is simply enabling/disabling the feature itself altogether, as well as the “Content & Privacy restrictions” toggle, and changing the level of allowed content between “Clean” and “Explicit”; I also want to highlight the fact that during the entire process, for the issue to be actually solved, users every time had to to restart their iPhone/iPad multiple times after changing a setting in “Screen time”, along with deauthorizing/authorizing (logging out and back in) their Apple Music account from the MusicKitJS SDK. The issue seems to always affect freshly created Apple accounts right from the start, we’re not aware of methods that can lead to the bug “coming back” and starting to happen again after being solved manually with the process above (meddling “randomly” with dashboards). It’s a pretty serious one because many of our users do not posses an Apple device and only use their Apple Music subscription on the Web and/or their Android device, meaning that the “Screen time” dashboard isn’t available for them. We’ve never been able to solve the problem on an Apple ID account solely by fiddling with the “Parental Controls” dashboard located in the Web version of the Apple Music’s settings page: tinkering with the “Screen time” settings was essential every single time, meaning owning an Apple device is essential to solve it. Last thing I’m adding is that the issue doesn’t seem to also affect listening to these explicit songs directly with the various first-party Apple Music clients (tested on the iOS native app, Android native app, and on the Apple Music WebApp). Steps to reproduce: on the Web, create a new Apple ID account and activate an Apple Music subscription (do not login with said account on an Apple device); go to the Apple Music WebApp settings page at music.apple.com/account/settings and make sure that the “Parental Controls” restrictions are turned OFF; open any explicit song in the Apple Music WebApp and confirm that playback is allowed; login and authorize the newly created account using any website/application integrated with the MusicKitJS SDK (v1 or v3, doesn’t matter); open the same explicit song as before (or any other) in said third-party client that uses the SDK and verify that playback doesn’t begin and an error “CONTENT_RESTRICTED: Content restricted” is logged in the console upon playing. Additional infos: Apple ID account region and language: Italy - Italian; Storefront affected: IT but possibly all of them; MusicKitJS versions affected: both v1 and v3; Browser where the issue was reproduced: Chrome v114. Attached you’ll find some informational screenshots. Thanks!
Posted
by
Post not yet marked as solved
1 Replies
518 Views
Hello Everyone, We've had an idea for a hardware controller for Logic X, and have already made prototypes that work with Garage Band and other applications. My question is - Does Apple have a development license available for Logic X? Thanks.
Posted
by
Post not yet marked as solved
0 Replies
525 Views
If a user has only added one song from an album in its library, the library album endpoint (/me/library/albums) will return this album. It does not make sense because the user did not add the full album to its library, only one song. Note that the Apple Music app is doing the same in its Library > Albums section. How to retrieve only those albums which have been added ?
Posted
by
Post not yet marked as solved
1 Replies
505 Views
Cannot get various songs to play and cannot figure out what is causing it. It appears to be certain albums don't play. For instance Eric Church's Chief album plays fine, but his Soul album does not play.
Posted
by
Post not yet marked as solved
0 Replies
546 Views
For some reason when I go through the same process as shown here: https://developer.apple.com/documentation/musickitjs/ using MusicKit JS to authorize a user, the popup opens a user logs in and then on the access request screen you click allow nothing happens. You can see in the network tab when inspecting that the usertoken is being generated but the popup isn't closing and no matter what I try I cannot extract the usertoken, any thoughts?
Posted
by
Post not yet marked as solved
1 Replies
527 Views
Apple Music Kit API will throw an Unauthorized 403 error when I log in successfully using an Apple Music account that has no Apple Music Subscription. After I successfully log in with my credentials, I will see a "Play full songs on the web" screen that indicates a successful log in. When I click "try it now" or "not now," the API will throw a "AUTHORIZATION_ERROR: Unauthorized." Authorization status will be set to 0, preview only will be set to false. Shouldn't the authorization be a success after the user has logged in? Ideally, the status should be a 1and preview true. I think what is missing is the consent screen which shows up only when the user is a subscribed member.
Posted
by
Post not yet marked as solved
0 Replies
381 Views
Trying to use the Apple Music API for mirroring playlists from spotify. Wondering if it will ever be on the roadmap to update/reorder playlists, or delete playlists/remove items using the API? Is this something that can't be handled or is it a business decision? I see that there is more flexibility with the MusicKit. Can we expect something like this in the future for the API? Thanks,
Posted
by
Post not yet marked as solved
1 Replies
363 Views
Greetings Fellow Humans, My player uses the v3 musickit-js library. I am trying to handle situations where a user tries to play explicit content in my player with an account that has content restrictions enabled. I don't see a mechanism to know if the toggle is set in the account. The only mechanism I see is to respond to a CONTENT_RESTRICTED error as handled by the callback to the function I provide as a callback to the mediaPlaybackError event. I have attached many callbacks (like bufferedProgressDidChange) and those all work, but this one never fires. music.addEventListener("mediaPlaybackError", onPlaybackError); Or music.addEventListener(MusicKit.Events.mediaPlaybackError, onPlaybackError); My onPlaybackError function, at least for debugging purposes, is: function onPlaybackError(e) { console.log("onPlaybackError"); console.log(e); } There are so many error conditions that are meant to be handled in this way but the callback never happens. Am I missing something? Why doesn't this callback fire? Thanks!
Posted
by
Post not yet marked as solved
0 Replies
475 Views
I want to add a small play button to play a song preview on my site. I don't want to use the embedded player because I want to style it custom. If I use the MusicKit Web library, do I need to add Apple branding legally? I don't see anywhere that says its required and I want to confirm.
Posted
by
Post not yet marked as solved
0 Replies
355 Views
Hello Apple Community, First, I'm asking this on the holidays, so happy holidays. Now I have some "fun coding time" and can do it because I have some holiday time. I'm new to this area and would greatly appreciate your expertise and guidance. Have mercy. I'm attempting to develop a simple application on my Mac OS to browse my playlists. However, I've encountered a few roadblocks that I struggle to navigate. I understand I need to implement two-factor authentication to access my playlists, for which an OAuth setup is required. This involves obtaining an Apple ID and a service ID and dealing with other complex elements. One particular challenge I'm facing is with the redirect URI in the OAuth process. It seems that it needs to be a valid domain, and I'm unsure if using a local server address like https://localhost:5000 would work. My goal is to create a basic Flask application that can interact with Apple's web authentication system, but I'm uncertain about the feasibility of this approach, given the domain restrictions. I would appreciate any advice or step-by-step guidance on the following points. What would be the simplest way to create an application (Swift, Python, or JavaScript) that can authenticate and enable browsing through my playlists? Any insights, tips, or examples you could share would be immensely helpful. I am eager to learn and look forward to your valuable suggestions. Anything step-by-step would be great, but I like to dream. Thank you so much for your time and assistance.
Posted
by
Post not yet marked as solved
2 Replies
430 Views
Hi! I've been working on a project in python that pulls in a bunch of my personal apple music playback history and library, etc. I can't find a single good/functional example on how to pull the Music User Token via the android method or MusicKit JS (web) - I've spent a lot of hours on this today, and no permutation of existing examples/documentation has worked. Any guidance would be much appreciated!! If you have a web app that pulls the music user token, I just need help understanding how to get to the token itself. Thank you!
Posted
by