MusicKit

RSS for tag

Let users play Apple Music and their local music library from your app using MusicKit.

MusicKit Documentation

Posts under MusicKit tag

205 Posts
Sort by:
Post not yet marked as solved
4 Replies
325 Views
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.
Posted
by gonzosan.
Last updated
.
Post not yet marked as solved
0 Replies
117 Views
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.
Posted Last updated
.
Post marked as solved
7 Replies
802 Views
Hi there, I'm creating an iOS 15 app, using the new Swift MusicKit beta. I've got basic "arbitrary" GET calls working with MusicDataRequest, like: fetch playlists and tracks. However, I cannot find good docs for adding tracks to a playlist in a user's library. I guess I could do this the "old way", but then I don't get the super-nice feature of auto dev/user tokens. So the question is: how to a POST, instead of GET in the following: let url = URL(string: "https://api.music.apple.com/v1/me/library/playlists/`\(targetPlaylistId)/tracks") let dataRequest = MusicDataRequest(urlRequest: URLRequest(url: url))
Posted Last updated
.
Post marked as solved
4 Replies
505 Views
Hi there! I am trying to fetch a record label's top and latest releases. For example, for "Big Machine Label Group", I can see the top and latest releases on Apple Music. I get the latest and top releases if I use the endpoint to get a catalog record label and query parameters to extend. https://api.music.apple.com/v1/catalog/us/record-labels/1552967199?views=top-releases,latest-releases However, I am getting nil for these values using MusicCatalogResourceRequest. Here's the code: let request = MusicCatalogResourceRequest<RecordLabel>(matching: \.id, equalTo: "1552967199") let response = try await request.response() guard let recordLabel = response.items.first else { return } print(recordLabel.topReleases) print(recordLabel.latestReleases) I cannot add properties for these either to get detailed info because I think there is no PartialMusicProperty when Root is RecordLabel. Can you point me to what I am doing wrong?
Posted
by snuff4.
Last updated
.
Post marked as solved
3 Replies
486 Views
Hi there! How do I go about accessing the details of the curator? For example, if I hit the following endpoint to access details about a playlist: https://api.music.apple.com/v1/catalog/us/playlists/pl.047294ae14a24e5993d1f7ab2b127188 Then, in the response, I see the curator containing the ID under relationships: "curator": {  "href": "/v1/catalog/us/playlists/pl.047294ae14a24e5993d1f7ab2b127188/curator",  "data": [   {    "id": "976439548",    "type": "apple-curators",    "href": "/v1/catalog/us/apple-curators/976439548"   }  ] } Using this ID, I can get more information like the editorial notes, kind, artwork, etc. If I use MusicKit to get details about the playlist: let id = MusicItemID("pl.047294ae14a24e5993d1f7ab2b127188") let request = MusicCatalogResourceRequest<Playlist>(matching: \.id, equalTo: id) let response = try await request.response() guard let playlist = response.items.first else { return } print(playlist.curatorName) It does not expose the Curator object but only the curatorName. How can I access the ID of the curator?
Posted
by snuff4.
Last updated
.
Post marked as solved
2 Replies
357 Views
Ive been looking at MusicKit hoping there is a way I can get a list of all Artists, Albums or Songs for a users Library. I can get these for a search term (see code), but what if I want to just return all Albums from the catalog ? I can't seem to find a method or search term to do this. Is it possible ? Thanks do {                 let searchRequest = MusicCatalogSearchRequest(term: "Muse", types: [Album.self])                 let searchResponse = try await searchRequest.response()                 print(searchResponse.albums.count)                 print(searchResponse.albums)             } catch {                 print("Failed to load albums")             }
Posted
by Dinalli.
Last updated
.
Post not yet marked as solved
2 Replies
547 Views
Hi, I am trying to use MusicDataRequest from MusicKit to get the user's library artists (https://api.music.apple.com/v1/me/library/artists). This works well, until I am trying to use pagination with it. The data returned by this endpoint contains a "next" property, which reads /v1/me/library/artists?offset=25. Replacing the URL as such resulting in https://api.music.apple.com/v1/me/library/artists?offset=25 no longer works, as the request returns an error: MusicDataRequest.Error( status: 400, code: 40008, title: "Invalid Path Value", detailText: "Unknown library resource type 'artists?offset=25'", ... ) It seems like the request cannot handle query parameters and considers them as part of the request's path. Is there any way to use query parameters with MusicDataRequest? Thanks for any response.
Posted Last updated
.
Post marked as solved
2 Replies
385 Views
I am using the MusicKit library for Swift. With this: let searchString = “led zeppelin iv deluxe edition” var albumSearchRequest = MusicCatalogSearchRequest(term: searchString, types: [Album.self]) The response from: let response = try await albumSearchRequest.response() returns no albums; however searching manually for that exact string in the Music App on either iOS or macOS will return results. This is really weird and problematic if one is trying to search for albums or tracks specific to certain albums.
Posted Last updated
.
Post marked as solved
3 Replies
441 Views
I am using Xcode 13.2 on MacOS 12.2. I have been building and running my app in Xcode for months with no issues. I stopped working on it for a couple of days while out of town. The next time I ran my app, I get this pop-up warning saying "This Mac can’t connect to Apple Media Services because of a problem with "my Apple ID email address" when the app uses MusicKit to search for an album. When I push "Apple ID Preferences...", it takes me there and another pop-up asks me to "sign in to Media Services using my Apple ID", even though I am already signed in. Once I sign in, my app continues to run. If I hit the "Later" button, the pop-up goes away and my app continues to run just fine. My computer was off when I was out of town, so no one did anything to it and no auto-updates were performed or anything. I tried signing out of iCloud, Apple Music... etc, restarting and signing back into everything as suggested by Apple customer service but that did not help. They say everything is fine with my Apple ID so it is an issue with Xcode. This happens every time I run my app in Xcode. Does anyone have any idea what is going on? Please help. Much appreciated!
Posted Last updated
.
Post marked as solved
6 Replies
616 Views
What is the best approach to retrieve playlists using MusicKit. I can't seem to guess from the docs how to use the API to accomplish this, as well as retrieving tracks from a playlist. I am in the process of migrating code from Apple Music API to MusicKit and I potentially could use MusicDataRequest to retrieve playlists using the Apple Music API endpoints, but I want to be sure there are no better alternatives. Sample code would definitely help.
Posted
by ridmaur.
Last updated
.
Post not yet marked as solved
1 Replies
230 Views
Hi there I am trying https://api.music.apple.com/v1/catalog/tr/albums?filter[upc]=upcvalue function for the Album details. But some UPC is not giving response. I am checking album details from iTunes Connect. No difference. I have attached 2 albums. Nazli Yarim (Album title) is working but other one not. What could be the problem? Thank you.
Posted Last updated
.
Post not yet marked as solved
4 Replies
417 Views
Hello, I'm using the Get Recently Played Tracks endpoint and I need to know when each track was played. Is there a way to request a timestamp? Thanks!
Posted Last updated
.
Post not yet marked as solved
2 Replies
149 Views
Hi Apple Engineers, In my app Caset, the album artwork is no longer displaying correctly, instead the console is printing with error: [Artwork] [MPArtwork] Failed to create directory at 'file:///var/mobile/Media/iTunes_Control/iTunes/Artwork/Caches/96x96/61/' with error: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “61” in the folder “96x96”." UserInfo={NSFilePath=/var/mobile/Media/iTunes_Control/iTunes/Artwork/Caches/96x96/61, NSUnderlyingError=0x280552dc0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}} Here is the code I am using to display the album artwork of the current item: @ObservedObject private var playerQueue = ApplicationMusicPlayer.shared.queue //In the BODY switch playerQueue.currentEntry?.item {     case .song(let song):     if let artwork = song.artwork {         ArtworkImage(artwork, width: 40, height: 40)        } case .musicVideo(let video):        if let artwork = video.artwork {           ArtworkImage(artwork, width: 70, height: 40)         }                case nil:        EmptyView()  } Related bug has been filed here: FB10189431 This unexpected behavior is new and was previously worked as expected in early versions of iOS 15.
Posted Last updated
.
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 Last updated
.
Post not yet marked as solved
6 Replies
594 Views
First let me state that this is not an issue with MusicKit, but I've raised a radar on this and have received 0 response, which is, sadly, kinda normal. However, it's kind of an important issue and my app relies on this feature to work consistently, so I thought I'd mention it and that the amazing @JoeKun might have an idea how to escalate it. Here's the problem in the iOS Music app: Add a song to an existing playlist Add another song to the same playlist Add another View the playlist More often than not, one of the newly added songs is missing in the playlist to which the song was added. There are entries in Recently Added for newly added songs that are not in the playlist where the songs were added. View the songs in the Music app on Mac. Query the playlist to get all songs via the Apple Music API. The Music app on Mac and the API results align, yet differ from iOS Music app. There are entries in Recently Added for newly added songs that are not in the playlist where the songs were added. In summary, when adding a song to a playlist using the iOS Music app, it sometimes does not add the song. For the record, I am awaiting the confirmation message each time a song is added. Adding tracks via the macOS Music app, seems to always work. This issue only occurs with the iOS app.
Posted Last updated
.
Post not yet marked as solved
5 Replies
302 Views
Hello, with the recent update of the Apple Music API allowing to retrieve artwork for artists, I wanted to know if it was possible to post an artwork when creating a playlist through the API? If so, what is the format and parameters to use and is it documented somewhere? Thanks for your help
Posted
by Anemost.
Last updated
.
Post not yet marked as solved
5 Replies
320 Views
Hello, I have a question regarding the update of playlists through the API. I haven't found this documented, but I prefer asking just in case I missed something. Is there an endpoint/parameter to add tracks to a playlist by overriding the tracks that are in it? I only found an endpoint to append tracks to a playlist, which is not enough for how my app works Thanks!
Posted
by Anemost.
Last updated
.
Post not yet marked as solved
4 Replies
278 Views
Hello, I'm using the Apple Music API to store tracks & albums links in my database and I need a way to determine if a track/album is available for purchase on iTunes or if it's a streaming one. I'm currently using the "playParams" attribute to determine it. If it is present I consider the track to be streaming, if it's not, I consider it to be a purchasable track. I'm not sure if this is the best way to do so, I'd gladly take your recommendations, maybe there's an attribute I missed on the API.
Posted
by Anemost.
Last updated
.
Post not yet marked as solved
3 Replies
229 Views
Hello! When creating a playlist we are getting an id which is the one in the user's library, it's not enough to create a link and share it with friends for example. To do so, we need a global id. The only way I found to generate this global id is by clicking on the share button of the playlist on Apple Music. After doing this manual action, the global id is properly returned by the Playlist endpoint on the Apple Music API. I wanted to know if there was a endpoint that could be called in order to generate this global id without having to go on the Apple Music app? Thanks for your help
Posted
by Anemost.
Last updated
.