Apple Music API

RSS for tag

Apple Music API integrates streaming music with Apple Music content.

Apple Music API Documentation

Posts under Apple Music API tag

98 Posts
Sort by:
Post not yet marked as solved
4 Replies
1.9k Views
I'm getting a variety of errors when I call prepareToPlay on the MPMusicPlayerController. Sometimes they happen, sometimes they don't. I'm trying to play songs from the Apple Music service. When I don't get the errors, it plays just fine. I have iOS v13.5.1 on my iPhone Xs and I'm using Xcode 11.5. This is my code: let applicationMusicPlayer = MPMusicPlayerController.applicationMusicPlayer applicationMusicPlayer.setQueue(with: [trackID]) applicationMusicPlayer.prepareToPlay(completionHandler:{ error in if let error = error { print(error.localizedDescription) return } DispatchQueue.main.async{ applicationMusicPlayer.play() } } These are the various errors I'm getting: [SDKPlayback] Failed to prepareToPlay error: Error Domain=MPMusicPlayerControllerErrorDomain Code=2 "Queue was interrupted by another queue" UserInfo={NSDebugDescription=Queue was interrupted by another queue} [SDKPlayback] Failed to prepareToPlay error: Error Domain=MPMusicPlayerControllerErrorDomain Code=9 "Preparing queue timed out" UserInfo={NSDebugDescription=Preparing queue timed out} [SDKPlayback] Failed to prepareToPlay error: Error Domain=MPMusicPlayerControllerErrorDomain Code=6 "Failed to prepare to play" UserInfo={NSDebugDescription=Failed to prepare to play} [SDKPlayback] applicationQueuePlayer _establishConnectionIfNeeded timeout [ping did not pong]
Posted
by
Post marked as solved
10 Replies
1.6k Views
I get this error message in the OS Logs when I run the sample code from this Apple link - https://developer.apple.com/documentation/sirikit/media/managing_audio_with_sirikit: Failed to fetch user token error: An unknown error occurred Return code is 0 too which seems strange as well. I've generated a JWT using swift run generateToken <team-id> <key-id> from the SwiftJWTExample package: JSON Web Token: "<token here>" Header: {"typ":"JWT","alg":"ES256","kid":"..."} Payload: {"iss":"...","iat":...,"exp":...} Signature: ... And have checked my team id and key id. I've enabled App groups for the extension and the main target, and Siri for the main target, and am running on an iOS 14 device, compiled with Xcode beta. Hope you can help me out!
Posted
by
Post not yet marked as solved
3 Replies
2.9k Views
Hi, I'm wondering if there's a way to use the iTunes store API to lookup a podcast by its ID and retrieve info on the latest 5 episodes. My base URL is: https://itunes.apple.com/lookup?id=1493846689&limit=5&sort=recent Based on the documentation provided here: https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/ my best guess is that I would need to specify an entity parameter in order to get information about each episode as opposed to the podcast as a whole. I've tried different entity values but to no avail. If anyone has any suggestions or workarounds that would be much appreciated, thank you.
Posted
by
Post not yet marked as solved
1 Replies
806 Views
Hi I have been working with the Reporter API 2.2 outlined as per the documentation here https://help.apple.com/itc/contentreporterguide/en.lproj/static.html#itcbe21ac7db . Everything is working fine however I've noted that the access token has an expiry of 180 days, therefore I would like to automate the process of generating new tokens every so often so that I do not have to do this manually for the number of accounts that I am handling and plethora of reports i am pulling out. I've tried numerous methods to automate this but ultimately none has worked. The following tries result in an instant null response: echo "user pass" | java -jar Reporter.jar p=Reporter.properties Sales.generateToken echo "user\npass\n" | java -jar Reporter.jar p=Reporter.properties Sales.generateToken java -jar Reporter.jar p=Reporter.properties Sales.generateToken < credentials.txt (echo "user"; sleep 1; echo "pass") | java -jar Reporter.jar p=Reporter.properties Sales.generateToken So directly piping does not work. I also wrote a shell script using spawn expect send workflow, although it looks like the prompts are being answered in order, there is no output at the end: #!/usr/bin/expect spawn java -jar Reporter.jar p=Reporter.properties Sales.generateToken expect "username"; send "user\n"; expect "password"; send "pass\n"; I also tried to write a python script to achieve the same thing but seem to be getting to the same problem. Is this not allowed? Is there a workaround or native support? To me it doesnt seem like this command takes any additional arguments. Thanks
Posted
by
Post not yet marked as solved
4 Replies
1.1k Views
Hello Apple World, I am working on an app that adds Apple Music songs to an MPMediaPlaylist. I was able to do this successfully in iOS 13.7. However, today I started testing on iOS 14.0.1 and the same code causes my app to freeze completely. print("PlaylistManager.addItem playlist \(playlist) identifier \(identifier) MPMediaLibrary.authorizationStatus() \(MPMediaLibrary.authorizationStatus().rawValue)") playlist.addItem(withProductID: identifier) { (error) in if error != nil {          print("An error occurred while adding an item to the playlist: \(error!.localizedDescription)") } } Output: "PlaylistManager.addItem playlist <MPConcreteMediaPlaylist: 0x2819dc4d0> identifier 1531532609 MPMediaLibrary.authorizationStatus() 3" Because I don't get any errors printed (the app just freezes up) and I don't see any crash logs in Devices and Simulators, I am not sure how to proceed. Is anyone else running into this issue with MPMediaPlaylist.addItem in iOS 14? Is there a general way to debug app freezes? Any help will be very much appreciated; Thank you in advance! Marvin
Posted
by
Post marked as solved
5 Replies
656 Views
I have an existing iOS app that uses MPMusicPlayerController systemMusicPlayer. When running on a MacBook with M1 processor, calling currentPlaybackTime returns 0 during play. Once paused, the correct playtime is returned. Anyone else having this issue or have an idea of how to get the correct playtime?
Posted
by
Post not yet marked as solved
4 Replies
1.2k Views
I'm working on an app that communicates with the Apple Music API. I'm attempting to run the app on a simulator (ios 14.2). When I run this code: SKCloudServiceController().requestUserToken(forDeveloperToken: developerToken) { (receivedToken, error) in       print(receivedToken ?? "No Token")       print(error)       guard error == nil else { return }       // the rest of the code that never gets called ...     } It prints this error: Error Domain=SKErrorDomain Code=9 "The latest Apple privacy policy has yet to be acknowledged" UserInfo={NSLocalizedDescription=The latest Apple privacy policy has yet to be acknowledged} And obviously I get no user token. How do I Acknowledge the latest Apple privacy policy? I am signed in with my apple Id in my simulator. I can use apple music on my regular iPhone and I can use Apple Music on OS X without Apple asking me to acknowledge Privacy Policy. Is there some way of provisioning user data on the app for testing purposes?
Posted
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
939 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
3 Replies
746 Views
Is there a known issue that the value of nowPlayingItem is always nil on Catalyst. The same app is working fine on iOS devices. Also the other MPMusicPlayerController functions like play, stop, and pause is working fine on Catalyst. I did not find any information that it should not work. Is this a known issue with existing workarounds. Thanks Marc
Posted
by
Post not yet marked as solved
0 Replies
839 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
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 marked as solved
5 Replies
1.2k Views
Hello everyone, I am trying to understand how to decode the JSON response returned by the suggestions/top results endpoint in MusicKit As you can see the response returns suggestions, which has two different types, Albums and Songs within the same 'suggestions' array. How can I decode the response even if there are different types using a single struct? { "results" : { "suggestions" : [ { "content" : { "attributes" : { "url" : "https:\/\/music.apple.com\/us\/artist\/megan-thee-stallion\/1258989914", "name" : "Megan Thee Stallion", "genreNames" : [ "Hip-Hop\/Rap" ] }, "id" : "1258989914", "relationships" : { "albums" : { "data" : [ { "href" : "\/v1\/catalog\/us\/albums\/1537889223", "type" : "albums", "id" : "1537889223" } ], "next" : "\/v1\/catalog\/us\/artists\/1258989914\/albums?offset=25", "href" : "\/v1\/catalog\/us\/artists\/1258989914\/albums" } }, "href" : "\/v1\/catalog\/us\/artists\/1258989914", "type" : "artists" }, "kind" : "topResults" }, { "content" : { "href" : "\/v1\/catalog\/us\/artists\/991187319", "attributes" : { "genreNames" : [ "Hip-Hop\/Rap" ], "url" : "https:\/\/music.apple.com\/us\/artist\/moneybagg-yo\/991187319", "name" : "Moneybagg Yo" }, "id" : "991187319", "type" : "artists", "relationships" : { "albums" : { "href" : "\/v1\/catalog\/us\/artists\/991187319\/albums", "data" : [ { "id" : "1550876571", "href" : "\/v1\/catalog\/us\/albums\/1550876571", "type" : "albums" } ], "next" : "\/v1\/catalog\/us\/artists\/991187319\/albums?offset=25" } } }, "kind" : "topResults" } ] } }
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