MusicKit JS

RSS for tag

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

Posts under MusicKit JS tag

120 Posts

Post

Replies

Boosts

Views

Activity

Music Kit Authorize without Subscription
I'm working on a streaming application using Music Kit. For the login, I'm using the "authorize" method which works fine when I use an account that has an Apple Music subscription. When I use an account that does not have a subscription I get prompted to try out Apple Music: If I click "not now" it doesn't return anything at all from what I see and it just stops my function altogether. This is the code I have setup to test this: const appleLogin = async () => {   console.log("Apple Login Called");   const userToken = await appleMusicInstance.value.authorize();   console.log("user token", userToken); }; When I log in using a subscription account it works fine, I get a token and I can stream full-length songs. When I click "not now" (with a non-subscription account) it just stops. Doesn't even show that my "userToken" received anything and nothing else in the function gets called. I'd like to have the ability for members to log in with their account whether they have a subscription or not and play either full length or previews based on their subscription status. What would be the best solution to this?
1
0
1.8k
Apr ’22
Apple Music API no longer working in our app.
Hi, We have an app which is a music social network, it worked fine on both Spotify/Apple Music up until the last few days, now the Apple Music search function is not working at all. Just wondering have we missed something has changed or any idea why it would be returning null. See image. We've tried other apps that use Apple Music and they seem fine, but nothing has changed on our app. So we know the API is working. We're puzzled. Does anyone have any idea, would be massively appreciated.
2
0
1k
Mar ’22
MusicKit JS webplayer
I am trying to create a webplayer for apple music and have run into some issues with actually playing the music. authorized.then((res) => { console.log(res); musicInstance.setQueue({ song: '1025212395' }).then((queue) => { console.log(queue) musicInstance.play(); }); },(rej) => { console.log("Failed to Recieve User Authorization") }) where authorized is the promise that is returned when the user logs in. I keep getting the following console errors when attempting to play any sort of media and have no clue how to debug it. Sometimes, it says DOM error and mediasource readyState is not 'open' Any ideas?
1
0
1k
Mar ’22
MusicKit JS - Invalid JWT validation
I have a web-app that is recently experiencing problems with users not being able to connect their Apple Music account. It was working perfectly up until now, it may be something with how my dependencies changed but I doubt that. In any case, once I invoke requestUserToken(), the tab is opened, and after authentication they get "Problem Connecting - There may be a network issue." Upon hitting "Try Again" the same error message appears, but this time the URL bar shows something along the lines of "ERROR_FAILED_TO_VERIFY_JWT&pod=10". What can be the reason for this?
5
0
1.5k
Mar ’22
Can MusicKit JS play queue continuously when phone is locked
Though I can get MusicKit JS to play continuously on desktop in the background, the player seems to stop at the end of a track on iPhone even if there are more tracks in the queue. Is this a known limitation? If so, are there any events I can listen to so that the app knows MusicKit has paused playback? If there is a solution I would appreciate any documentation or examples.
1
0
710
Mar ’22
JWT works for Apple Music API but doesn't work for MusicKit
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 :)
2
0
2.0k
Mar ’22
Getting editorialVideo from MusicKit Request
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?
1
0
1k
Feb ’22
Could Apple create properly working Recently Played Endpoint?
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.
0
1
899
Dec ’21
MusicKit PLAY_ACTIVITY error popups
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
2
0
2.0k
Dec ’21
Apple Music/Music Kit: how to get song IDs from regular URLs?
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?
3
0
4.9k
Nov ’21
Use token from “sign in with apple” to query apple music api
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
1
0
2.5k
Nov ’21
Do I need to encrypt an Apple Music API JWT token?
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!
0
0
1k
Nov ’21
Error when authenticate from ember (?)
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>
2
0
707
Oct ’21
musickit js albums undefined for user
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'); }); });
1
0
713
Oct ’21
Where do i put the user token for api request
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); } } );
1
0
991
Oct ’21
Tinder app creation
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!
1
0
909
Oct ’21
MPMusicPlayerController play user playlist (library playlist)
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?
5
0
1.2k
Jul ’21
MusicKit JS: Chromium based browsers only get 30 second previews
I've got a little MusicKit JS page I'm working on and I'm running into this issue where the only browser that will play full tracks is Firefox (and Safari, obviously). I've tried several Chromium based browsers and MusicKit plays 30 seconds previews instead of full tracks. Other widevine content works in those browsers. I've tried: Brave Chrome Vivaldi Of course, the v2 library works on music.apple.com in Brave and others. v1 and v2 libraries behave the same for me in my page. The library knows it's authenticated. I can browse content in the catalog and the user's library. I just can't play more than 30 seconds at a time. Any crazy ideas? Thanks
1
0
870
Jul ’21
Music Kit Authorize without Subscription
I'm working on a streaming application using Music Kit. For the login, I'm using the "authorize" method which works fine when I use an account that has an Apple Music subscription. When I use an account that does not have a subscription I get prompted to try out Apple Music: If I click "not now" it doesn't return anything at all from what I see and it just stops my function altogether. This is the code I have setup to test this: const appleLogin = async () =&gt; {   console.log("Apple Login Called");   const userToken = await appleMusicInstance.value.authorize();   console.log("user token", userToken); }; When I log in using a subscription account it works fine, I get a token and I can stream full-length songs. When I click "not now" (with a non-subscription account) it just stops. Doesn't even show that my "userToken" received anything and nothing else in the function gets called. I'd like to have the ability for members to log in with their account whether they have a subscription or not and play either full length or previews based on their subscription status. What would be the best solution to this?
Replies
1
Boosts
0
Views
1.8k
Activity
Apr ’22
Apple Music API no longer working in our app.
Hi, We have an app which is a music social network, it worked fine on both Spotify/Apple Music up until the last few days, now the Apple Music search function is not working at all. Just wondering have we missed something has changed or any idea why it would be returning null. See image. We've tried other apps that use Apple Music and they seem fine, but nothing has changed on our app. So we know the API is working. We're puzzled. Does anyone have any idea, would be massively appreciated.
Replies
2
Boosts
0
Views
1k
Activity
Mar ’22
MusicKit JS webplayer
I am trying to create a webplayer for apple music and have run into some issues with actually playing the music. authorized.then((res) => { console.log(res); musicInstance.setQueue({ song: '1025212395' }).then((queue) => { console.log(queue) musicInstance.play(); }); },(rej) => { console.log("Failed to Recieve User Authorization") }) where authorized is the promise that is returned when the user logs in. I keep getting the following console errors when attempting to play any sort of media and have no clue how to debug it. Sometimes, it says DOM error and mediasource readyState is not 'open' Any ideas?
Replies
1
Boosts
0
Views
1k
Activity
Mar ’22
MusicKit JS - Invalid JWT validation
I have a web-app that is recently experiencing problems with users not being able to connect their Apple Music account. It was working perfectly up until now, it may be something with how my dependencies changed but I doubt that. In any case, once I invoke requestUserToken(), the tab is opened, and after authentication they get "Problem Connecting - There may be a network issue." Upon hitting "Try Again" the same error message appears, but this time the URL bar shows something along the lines of "ERROR_FAILED_TO_VERIFY_JWT&pod=10". What can be the reason for this?
Replies
5
Boosts
0
Views
1.5k
Activity
Mar ’22
Can MusicKit JS play queue continuously when phone is locked
Though I can get MusicKit JS to play continuously on desktop in the background, the player seems to stop at the end of a track on iPhone even if there are more tracks in the queue. Is this a known limitation? If so, are there any events I can listen to so that the app knows MusicKit has paused playback? If there is a solution I would appreciate any documentation or examples.
Replies
1
Boosts
0
Views
710
Activity
Mar ’22
JWT works for Apple Music API but doesn't work for MusicKit
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 :)
Replies
2
Boosts
0
Views
2.0k
Activity
Mar ’22
Getting editorialVideo from MusicKit Request
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?
Replies
1
Boosts
0
Views
1k
Activity
Feb ’22
Could Apple create properly working Recently Played Endpoint?
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.
Replies
0
Boosts
1
Views
899
Activity
Dec ’21
MusicKit PLAY_ACTIVITY error popups
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
Replies
2
Boosts
0
Views
2.0k
Activity
Dec ’21
Question about a feature in an app
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.
Replies
1
Boosts
0
Views
815
Activity
Nov ’21
Apple Music/Music Kit: how to get song IDs from regular URLs?
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?
Replies
3
Boosts
0
Views
4.9k
Activity
Nov ’21
Use token from “sign in with apple” to query apple music api
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
Replies
1
Boosts
0
Views
2.5k
Activity
Nov ’21
Do I need to encrypt an Apple Music API JWT token?
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!
Replies
0
Boosts
0
Views
1k
Activity
Nov ’21
AppleJS & MusicKit JS
Is it possible to exchange applejs authentication code for a music user token? Basically - Is it possible to use apple signin with music kit without users needing to sign in twice to apple?
Replies
1
Boosts
0
Views
1.2k
Activity
Oct ’21
Error when authenticate from ember (?)
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>
Replies
2
Boosts
0
Views
707
Activity
Oct ’21
musickit js albums undefined for user
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'); }); });
Replies
1
Boosts
0
Views
713
Activity
Oct ’21
Where do i put the user token for api request
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); } } );
Replies
1
Boosts
0
Views
991
Activity
Oct ’21
Tinder app creation
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!
Replies
1
Boosts
0
Views
909
Activity
Oct ’21
MPMusicPlayerController play user playlist (library playlist)
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?
Replies
5
Boosts
0
Views
1.2k
Activity
Jul ’21
MusicKit JS: Chromium based browsers only get 30 second previews
I've got a little MusicKit JS page I'm working on and I'm running into this issue where the only browser that will play full tracks is Firefox (and Safari, obviously). I've tried several Chromium based browsers and MusicKit plays 30 seconds previews instead of full tracks. Other widevine content works in those browsers. I've tried: Brave Chrome Vivaldi Of course, the v2 library works on music.apple.com in Brave and others. v1 and v2 libraries behave the same for me in my page. The library knows it's authenticated. I can browse content in the catalog and the user's library. I just can't play more than 30 seconds at a time. Any crazy ideas? Thanks
Replies
1
Boosts
0
Views
870
Activity
Jul ’21