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

37 Posts
Sort by:
Post not yet marked as solved
2 Replies
926 Views
Often we get the error below when we invoke skipToPreviousItem or skipToNextItem. Can anyone shed any light on what it means or how to fix it? These errors don't seem to actually stop the music playing, so it would be good even if there was a way we could not show the alert popups. It would also be good if anyone knows how to control the kit to make it not show error dialog (like using a try-catch error before it shows)? PLAY_ACTIVITY: A play stop() method was called without a previous play() descriptor Anyone seen this and been able to fix it? Thanks
Posted
by
Post not yet marked as solved
2 Replies
903 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
2 Replies
940 Views
We're using  https://developer.apple.com/documentation/musickitjs to authorize Apple music, on Desktop it opens a new window to authorize to apple. But It's NOT working on mobile In-App Browser (both iOS &amp; Android), probably because on mobile messenger, it's not possible to allow the opening of multiple windows. Are we missing something here? Any workaround for it? Has anyone done that?
Posted
by
Post not yet marked as solved
1 Replies
1k Views
A while ago I started developing a hobby web app aroune Apple Music, and I created a script to generate my JWT and I used it with MusicKit and with Apple Music API and everything was working perfectly fine, and now I came back and wanted to continue the project from where I left off and I tried using the same code (I literally ran the same script without changing anything, it already had the p8 file and the team ID and app key etc..) so I generated a new JWT with that script, and for the Apple Music API it's working as it should, but for the MusicKit (only tried for web) it seems to not work. For some reason when I try to authorize the user (w/ MusicKit for web) it does open the authorization pop up window and after the user enters their Apple Music credentials and tries to login, the pop up windows says there's an error, and in the URL I can see an "error" query param with the value "ERROR_FAILED_TO_VERIFY_JWT" (but the JWT is clearly working fine with Apple Music API...) I already opened an issue report on the feedback assistant, but I was thinking maybe someone has/had the same problem and knows how to solve it or what causes it :)
Posted
by
Post not yet marked as solved
0 Replies
840 Views
Context I am trying to make webservice that fetches the users name and email from his Apple account and place a Song or Artist in his library. For adding a Song to the library I found this apple-music-api. library. To make requests on behalf of a user you need to request a user token with Apple MusicKit JS library. For fetching the name and email of the user I use this oauth2 client that uses the signin with Apple functionality. Problem A Using the apple music kit... I can not query any user profile data. At least I cannot seem to find an example of this. If there is a possibility to get user email and name using this route? B Using the Sign in with Apple oauth flow I receive an access token which contains the name and email. But I cannot use the token to query the apple music api. It seems their scopes are limited to name and email...and no music or something. Is there a possibility to get an user token that can be user on the music api? C Are there any other possibilities to accomplish this without requiring the user to sign in twice on apple (once for the email and once for pushing the Song to his library) PS: I also asked this question on stackoverflow https://stackoverflow.com/questions/67649023/use-token-from-sign-in-with-apple-to-query-apple-music-api
Posted
by
Post not yet marked as solved
3 Replies
1.2k Views
I'm very happy that Apple Music now supports lossless audio. However, the applications we have created using MusicKit and MusicKit JS currently do not seem to play in lossless or high-resolution formats. When will we developers be able to use MusicKit and MusicKit JS to play songs in lossless and hi-res formats?
Posted
by
Post not yet marked as solved
5 Replies
650 Views
I am finding it impossible to play a library playlist using the MPMusicPlayerController class. I can play catalog playlists without any issues, but and user library specific playlist or song fails with "failed to prepare for play".  MPMusicPlayerController.applicationMusicPlayer.setQueue(with: [playlistId]) MPMusicPlayerController.applicationMusicPlayer.play() The above works so easily for playlists retrieved with: https://api.music.apple.com/v1/catalog/au/playlists. When trying to play a playlist from https://api.music.apple.com/v1/me/library/playlists it fails. Any ideas?
Posted
by
Post not yet marked as solved
1 Replies
604 Views
I would like to create presave feature on my app with Apple Music API. On this article, developer token has an option to set expiration date but music user token don't. Does music user token has an option to set expiration date? If not, how do I know expiration date on music user token?
Posted
by
Post not yet marked as solved
1 Replies
322 Views
I am trying to get the list of albums from a user's library. I use this code. The user is able to successfully login but the albums property of the library object is undefined. How do I get the list of albums for a user? music.authorize().then(function() { music.api.library.albums.then(function(cloudAlbums) { // user's cloudAlbums console.log('cloudAlbums'); }); });
Posted
by
Post not yet marked as solved
1 Replies
290 Views
i have this sample code to get the users albums, but where do i put the usertoken on the request.get call. I can't find anywhere online that shows where it goes. "use strict"; const fs = require("fs"); const jwt = require("jsonwebtoken"); const request = require("request"); const privateKey = fs.readFileSync("AuthKey.p8").toString(); const jwtToken = jwt.sign({}, privateKey, { algorithm: "ES256", expiresIn: "180d", issuer: "", header: { alg: "ES256", kid: "" } }); console.log("token:", jwtToken, "\n"); var url = ""; url = "https://api.music.apple.com/v1/me/library/albums"; request.get( { url: url, auth: { bearer: jwtToken }, json: true }, (err, httpResponse, body) => { if (err) { console.error(err); } else { console.log(body.results.albums.data); } } );
Posted
by
Post not yet marked as solved
1 Replies
417 Views
Hi guys, I'm trying to build an app that functions similarly to tinder and i'm asking for some tips on that creation. I just need some brainstorm ideas of how to best create a dating swipe type app like tinder? Does anyone have any ideas on how tinder was created? How many view controllers, which is the best view controller to use/create? anything would be helpful!
Posted
by
Post not yet marked as solved
1 Replies
369 Views
Hello, whenever I try to authenticate a MusicKit instance the popup alway shows 'Problem Connecting There may be a network issue. '. When reloading the popup it shows the login screen, but after I did log in it shows the same error page again. On the first error screen I get the following error in the console, which seams to be an errors from ember js. Error while processing route: woa Failed to construct 'URL': Invalid URL TypeError: Failed to construct 'URL': Invalid URL TypeError: Failed to construct 'URL': Invalid URL On the second error page I find the following error in the console: Error while processing route: oauth-screen This happens both on Brave and Safari. Is this a bug or did i something wrong? My Code: <html> <head> <script src="https://js-cdn.music.apple.com/musickit/v1/musickit.js"></script> </head> <body> <script> document.addEventListener('musickitloaded', function () { MusicKit.configure({ developerToken: 'My token', debug: true, suppressErrorDialog: false }); let music = MusicKit.getInstance(); music.authorize().then(function (response) { console.log(response); }); }); </script> </body> </html>
Posted
by
Post not yet marked as solved
3 Replies
871 Views
The Apple Music API provides a service to fetch a song via an identifier, as detailed in their documentation in this format: https://api.music.apple.com/v1/catalog/us/songs/900032829 However, I noticed that when linking to a song on Apple Music, the link looks like this: https://music.apple.com/us/album/take-on-me-1985-12-mix-2015-remastered/1035047659?i=1035048414 What I am unable to do (unless without using the Spotify API to look up the IRSC code) is to extract the song ID from the regular music URL. What is the best way to do this?
Posted
by
Post not yet marked as solved
1 Replies
436 Views
Hello i have a question about implementing apple music into my mobile app, is there a way i could have the user sign into apple music api on my app and then it directs them to my exact playlist i want to be played. basically i want someone to be able to listen to apple music on my app but only a certain playlist.
Posted
by
Post marked as solved
12 Replies
1.2k Views
If I make a request to https://api.music.apple.com/v1/storefronts/us with the proper developer jwt token in the header, I receive the a successful response with a list of store fronts. If I remove the token, I do get back a 401 error. If I call any other catalog base query, I am getting back a 500 error. For instance: https://api.music.apple.com/v1/catalog/us/albums/310730204 returns a 500 error with the body being {"message":"An unexpected error occurred"} I'm not sure what I can do to fix this. Please help.
Posted
by
Post not yet marked as solved
0 Replies
394 Views
I've used JWT before but first time with the Apple Music API. I put together a JWT from jwt.io with the ES256 algorithm and running it through Postman or curl, I get a generic 500 error with "An unexpected error occurred". Reading back through the documentation, I read, "After you create the token, sign it with your MusicKit private key. Then encrypt the token using the Elliptic Curve Digital Signature Algorithm (ECDSA) with the P-256 curve and the SHA-256 hash algorithm." I haven't seen much about encrypting the token in any other posts. Do I need to sign the token and then encrypt the whole thing? Thanks!
Posted
by
Post not yet marked as solved
0 Replies
276 Views
I already submitted bug by Feedback Assistant. Hopefully, Apple engineers will read this. What is wrong?: Lack of date and time of song's access. Without this it's impossible to scrobble. When I play song using MusicKitJS v1 they are not reflected in history at all. If I play the same song several times in loop endpoint suggests song was played only once. Also there is a mess in documentation. Official page of MusicKit redirects to JS version 3 while Apple Developer Documentation lists MusicKit v1, I assume there was no version 2 and 3 is in beta? Since there is some progress e.g ability to play radio stations in JSv3 it would be nice if main Apple Music API was also updated and finally gaves us ability to delete song from playlist.
Posted
by
Post not yet marked as solved
1 Replies
496 Views
Working with MusicKitJS V3, and with the extend key being used, I'm trying to request the animated editorialVideo in my app. this.musicKitInstance.api.music( `v1/catalog/${this.musicKitInstance.storefrontId}/albums/${id}`, { extend: 'artistUrl,composerUrl,trackCount,editorialVideo,editorialArtwork', } ) Looking at how music.apple.com does it, this appears to be the correct format, but the API never returns the editorialVideo in the response. Which stands out as the API will return the artistUrl in the response, just not the editorialVideo. Is this a limitation of the API?
Posted
by