Post not yet marked as solved
When working with embedded web content inside a native app, any calls to MusicKit.authorize will not be properly authenticate.
Calling authenticate will open Safari, allow the user to login, then ask for user confirmation, but the window will not navigate back to the native app.
Is it expected that developers would have to enable associated domains for the native app?
Post not yet marked as solved
Hello!
I am currently working on a react.js application that is integrating with the MusicKit v3 library. I have followed the documentation to generate a JWT for MusicKit and add the library to my application.
Using my token I am able to successfully retrieve song information from the Apple Music API, but I am having trouble with authentication.
When I call music.authorize() and successfully go through the Apple sign in popup, I am receiving the following 403 error:
https://play.itunes.apple.com/WebObjects/MZPlay.woa/wa/webPlayerLogout 403 musickit.js:44 Uncaught (in promise) AUTHORIZATION_ERROR: Unauthorized
After stepping through the music kit API and login popup with breakpoints, I am seeing that the music user token is null, despite the login popup succeeding and returning a proper token/response:
{"isAppleMusicSubscriber":"true","musicUserToken":"Ak4ItOgRRRG2y6xgA/OeWQPK0RqPQ/esAJkRN0B/Ua/AWLT52tLhd2TfzMK6uhH+Nczvd7wjYDM1UewG/NledKtimwlrR+s5tdQPk/FG28zqhBqXZ12q6LC516w8ELZDwv5T61kV8xiJ1KSO1q4pGi01JO7SuPMtOqB/QsycYj+xNnrYUEwlP5tm/zxfg7bWmvuWMwfUruYR+A1U9FdXZsdIITVmxCjiHg8ro9xXRzl6Txhsag\u003d\u003d","cid":"REDACTED","itre":"REDACTED","supported":"REDACTED"}
I have tested my application with multiple Apple Music users who have paid subscriptions. All accounts are receiving this same error.
I have tried regenerating my JWT token multiple times following various guides. My latest attempt used the following node library and parameters:
var jwt = require('jsonwebtoken');
var fs = require('fs');
var privateKey = fs.readFileSync('./AuthKey_MYKEY.p8');
let now = new Date();
let nextMonth = new Date(now.getFullYear(), now.getMonth() + 1, now.getDate());
let nowEpoch = Math.round(now.getTime() / 1000); // number of seconds since Epoch, in UTC
let nextMonthEpoch = Math.round(nextMonth.getTime() / 1000); // number of seconds since Epoch, in UTC
var payload = {
iss: 'REDACTED', // TEAM ID
iat: nowEpoch,
exp: nextMonthEpoch
};
var options = {
algorithm: 'ES256',
header: {
alg: 'ES256',
kid: 'REDACTED' // KEY ID
}
};
jwt.sign(payload, privateKey, options, function(error, token) {
console.log(error);
console.log(token);
});
I have a valid App Identifier created with the MusicKit App Service enabled.
I am stuck! I have no other ideas on the possible root cause here. Is there something I am missing? I have a mobile app currently in Test Flight - does this app need to be released to the app store? I am out of guesses!
Any support here would be greatly appreciated!
Thank you for your time.
Patrick
When attempting to authenticate with the musickit-js v3, the page that gets loaded from authorize.music.apple.com results in an error "Cannot parse response"
On the desktop, this does not happen.
The authentication code in question is
async login() {
const mkInst = MusicKit.getInstance();
await mkInst.authorize();
}
Not sure if this is limited to V3, as it's technically not officially released, but figured it was worth bringing to attention.
Post not yet marked as solved
The documentation states that setting this property to true makes the player only play previews, even when authorization is available.
I am using it like this:
async function playPreview(songId) {
const music = window.MusicKit.getInstance();
music.previewOnly = true;
await music.setQueue({song: songId, startPlaying: true});
}
This still makes the entire song play.
I have cross-checked that I am indeed loading MusicKit v3 (MusicKit.version returns '3.2226.3-prerelease').
Is the documentation wrong here, or am I missing something?
Post not yet marked as solved
I'm trying to stream an array of Apple music songs that are not tied to a single playlist. I have all the id's of these songs and I can play them individually if I use "setQueue" such as this:
await musicKit.value.setQueue({
songs: ["1616228595", "1564530724"],
autoplay: true,
});
After the first song finishes playing it just stops altogether. How can I have the next song in the array play? I'm able to use:
await musicKit.value.skipToNextItem();
await musicKit.value.skipToPreviousItem();
And that works fine to toggle between the songs in the array, but I haven't found anything that shows an example of how this would be done with an array of songs such as I have. What do I need to add in order to get this playing songs back to back in from the song array?
Post not yet marked as solved
Hey All,
I am in the middle of developing a little web app using MusicKit JS, and I deleted all my playlists so I could do a little testing.
But when I get all library playlists, the query returns 81 phantom playlists. The playlists don't have names in the JSON, so I can't work out their source. It doesn't show any of the playlists I have added and just keeps returning 81 phantom library playlists.
When I tested my code using another person's Apple ID, it works perfectly, retuning all the playlists in their library.
Is there a way to reset the library or fix this?
I am using V1 of the MusicKit library.
Thanking everyone in advance.
Jacko
I'm trying to use the seekToTime instance method as shown here: https://developer.apple.com/documentation/musickitjs/musickit/player/2992768-seektotime
I don't know what "time" is, is this in seconds or milliseconds? I assume it's in seconds but I figure I'd ask anyway.
I am currently using it in this way:
await musicKit.play();
await musicKit.seekToTime(10);
This technically works, although it plays first from the start and then abruptly changes to play based on the "time" provided in the seekToTime method.
I tried using the seek method before playing but that throws an error. Same thing if I "chain" these together using seekToTime first "then" play the music.
Is there a "smoother" way to start playing at a specific time without this abrupt change?
Is there any sign of an update to MusicKit JS? The 1.x version still seems to be the only one available despite updates to the iOS and MacOS SDKs. The 1.x version has been fairly unreliable for me and I've paused updates to Apple Music support in my app in hopes that a better version is coming soon.
Post not yet marked as solved
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 & 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?
Post not yet marked as solved
I'm testing out a dynamic song list to be queued up with Music Kit JS. When testing with a few tracks everything seemed to be working fine but then I ran into this error:
The Id in question is Nirvana's "Smells Like Teen Spirit". I retrieved this Id through the Apple Music API and I double-checked it to make sure it was correct and it is. This appeared for a few tracks.
I used this API endpoint to verify it was correct:
https://api.music.apple.com/v1/catalog/us/songs?filter[isrc]=USGF19942501
this one as well:
https://api.music.apple.com/v1/catalog/us/songs/483164390
The ISRC matches that Id, and I can see it directly from the apple id as well.
Why does this appear? From everything I see that song does exist and I can play it fine on Apple Music, so why can't I play this through the Music Kit JS instance?
Post not yet marked as solved
I'm trying to figure out if an event gets called whenever I'm streaming with the music kit player and I reload the page. I'm using Chrome and when I reload the page the streaming music stops and says the browser prevented playing without user interaction.
Events I have listeners for include:
mediaPlaybackError
nowPlayingItemDidChange
playbackStateDidChange
queueIsReady
queueItemsDidChange
mediaCanPlay
Each of these are associated with a console message so I can track when they get called. This is what appears in my console when I start a playlist:
I thought that the "mediaPlaybackError" would be called but it wasn't, and no other errors seem to pop up. The documentation here:
https://developer.apple.com/documentation/musickitjs/musickit/events doesn't really explain much about the events.
Post not yet marked as solved
Hi!
Since a couple of hours or yesterday, there's no more "next" value for the pagination when retrieving playlist tracks. Only a "meta" with a "total" value.
Could you please look at this ASAP?
Thank you.
Post not yet marked as solved
I'm using MusicKit JS v1, and I've noticed that I can't seem to get playlists with more than 100 songs to shuffle and play past the first 100. The limitation is that the API call made with MusicKit JS default fetch (I'm using the tracks relationship in a playlist) is capped at 100, and I get a 400 error code whenever I try to raise the limit. On the other hand, I can't figure out how to just get the next 100, because I can't seem to get the offset parameter to work correctly in MusicKit JS either. Any recommendations?
For reference, something like the below just doesn't work (it only retrieves the first 100 songs or throws an error).
await appleMusicState.musicKit.api.playlist(selectedPlaylist.id, {limit: 200})
.then(playlist => {
console.log(playlist);
})
nor does directly trying to setQueue with the playlist ID
await appleMusicState.musicKit.setQueue({playlist: selectedPlaylist.id});
Post not yet marked as solved
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?
Post not yet marked as solved
Hi,
I'm developing a B2B web-app which will be only used internally by other businesses that already are subscribed to the Apple Developer Program.
This app has to communicate with the MusicKit API.
I'd like to know if I can ask those business to create a Media ID from their developer account and insert their Team ID, Key ID and Secret in my app, in order to be able to generate a token. I'd like to do so in order to avoid any possible request rate limit on my account in case I made the app use my Media ID for all their requests.
Is it possible or doing so I may violate any Apple license aggreement? I can't find this answer anywhere
Post not yet marked as solved
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?
Post not yet marked as solved
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.
Post not yet marked as solved
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?
Post not yet marked as solved
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?
Post not yet marked as solved
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.