Post not yet marked as solved
I'm developing an app which utilises playback from the Apple Music catalogue using MusicKit. Playback works fine however, whenever the playback state changes the ApplicationMusicPlayer.shared.state.objectWillChange publisher is fired twice. Moreover, with each emit the ApplicationMusicPlayer.shared.state is different.
An example:
Music is playing in my app.
Music is paused. (Through any method of pausing)
The objectWillChange publisher is called twice.
In first call state is .playing
In the second call state is .paused
The same happens if playback is then resumed except the states switch. First, .paused and then .playing.
I'm using Combine's .sink() method. I've checked for accidental duplicate subscriptions but there is only one. Is this the intended behaviour or is this an issue?
Post not yet marked as solved
Hello, am trying to use musickit.
Am Curious, since am only interesting in musickit api web, dose that mean i will have to pay for developers' fees ?
Post not yet marked as solved
In this thread it has been stated that getting artist artwork through the MusicKit api isn't allowed because of copyright issues. My question is:
Is using the Apple Music REST api to get album artwork via the OpenGraph API also disallowed such that my app would be rejected? Wonder if I should pursue this option that I found or if I need to find another way? Seems like the answer would be no, but wanted to double check.
Thanks for your response, this is my first app that I'm trying to publish to the store and I'd like to avoid getting an instant rejection for something like this.
Code snippet:
import MusicKit
import Foundation
import OpenGraph
extension Artist {
func artwork(width: Int = 1024, height: Int = 1024) async -> URL? {
let id = self.id.rawValue
let countryCode = try? await MusicDataRequest.currentCountryCode
let url = URL(string: "https://music.apple.com/\(countryCode ?? "us")/artist/\(id)")!
return await withCheckedContinuation { continuation in
OpenGraph.fetch(url: url) { result in
switch result {
case .success(let og):
let image = og[.image]?.resizeArtwork(width: width, height: height)
if let image = image, let url = URL(string: image) {
continuation.resume(returning: url)
} else {
continuation.resume(returning: nil)
}
case .failure(_):
continuation.resume(returning: nil)
}
}
}
}
}
extension String {
func resizeArtwork(width: Int, height: Int) -> String? {
do {
let regex = try NSRegularExpression(pattern: "/\\d+x\\d+cw", options: .caseInsensitive)
let newImage = regex.stringByReplacingMatches(in: self, options: [], range: NSRange(0..<self.utf16.count), withTemplate: "/\(width)x\(height)cc")
return newImage
} catch {
return nil
}
}
}
Post not yet marked as solved
I am trying to follow along with this in order to auto generate my dev token on requests to MusicKit, but I am getting an error about by identifier, which was configured
Link:
https://developer.apple.com/documentation/musickit/using-automatic-token-generation-for-apple-music-api
Error:
2022-04-26 14:12:06.353589-0400 [6885:431407] [DataRequesting] Failed retrieving developer token: Error Domain=ICErrorDomain Code=-8200 "Media API Token Service responded with status code: Not Found (404). This suggests that "<set_bundle_ID>" was likely not registered as a valid client identifier." UserInfo={NSDebugDescription=Media API Token Service responded with status code: Not Found (404). This suggests that "<set_bundle_ID>" was likely not registered as a valid client identifier., NSUnderlyingError=0x2827669a0 {Error Domain=AMSErrorDomain Code=301 "Invalid Status Code" UserInfo={NSLocalizedDescription=Invalid Status Code, AMSURL=https://sf-api-token-service.itunes.apple.com/apiToken?REDACTED, AMSStatusCode=404, AMSServerPayload={
message = "Client not found";
status = 40402;
}, NSLocalizedFailureReason=The response has an invalid status code}}}. Throwing .developerTokenRequestFailed.
error getting token
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
I noticed that MusicKit updated so that you do not need to create any JWT tokens anymore (it's automatic).
But since it's automatic, how would I get the current user's recently played music?
I know you can do it with the API, but how would you do it with MusicKit (assuming you have MusicKit setup and running properly already)?
https://developer.apple.com/documentation/applemusicapi/get_recently_played_resources
I've been looking through the MusicKit documentation and can't find a single reference to it.
https://developer.apple.com/documentation/musickit
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 supported Relationship Views for Albums in the API include appears-on, other-versions, related-albums, related-videos, but it doesn't support more-by-artist, this data is available when viewing the album in the Apple Music app and would be very useful if it was available in the Apple Music API and possibly MusicKit as well with new iOS update.
Post not yet marked as solved
Is it possible to play songs/playlists on another device on the same account of the user.
Effectively, remote control.
ex: I own a Mac Book and an iPad, my iPad is connected to speakers, I want to stop and start playing music on the iPad using my Mac Book, through APIs.
Post not yet marked as solved
Hi there!
I have been trying to play the music videos we get from Apple Music API and have been unsuccessful.
Here's my code:
var video: MusicVideo
var body: some View {
VideoPlayer(player: AVPlayer(url: video.url!))
}
I know the URL from the MusicVideo is not in a music format but just the URL to the video in the Apple Music catalog.
How do I go about playing it without using something like MPMusicPlayerController.systemMusicPlayer.openToPlay(queueDescriptor) and provide an in-app experience (and not take the user to the Apple Music app)?
Post not yet marked as solved
given a song storeId from a storefront other than my own. Is there a apple music API call to determine if the song is playable.
For example song A is from the gb storefront and my apple music account uses storefront au. Can I play this track without getting a playback error
Whether the apple Music kit provides support to download audio or video songs?
Post not yet marked as solved
Is there a way to get the time a user has played a track using Apple Music REST Api ?
Post not yet marked as solved
Do we have any development allowance/tools for playback from Apple Music without a necessity to pay for the subscription?
I am making a media player for Apple iOS and wanted it to be able to pull my music library using an API. The closest thing I found to this is this:
https://developer.apple.com/musickit/
However, I don't know if it will allow users to play their music purchased by apple. Does anyone know how to do this so the user logs into their apple account through my app and then has complete access to their movies, tv shows, and music?
Any answers are really appreciated I did my best to find the answer to this and know its annoying to ask these questions when google or apple has it documented somewhere.
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
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
Hi there,
I can see dateAdded when looking at the response of a get library playlist request via the Apple Music API, but this does not appear to exist on any tracks within a given library playlist.
I'm assuming that this just isn't there, but I'm asking here, in case I've missed it.
Thanks.