MusicKit

RSS for tag

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

MusicKit Documentation

Posts under MusicKit tag

126 results found
Sort by:
Post not yet marked as solved
13 Views

Incorrectly Decodable response for MusicItemCollection

I'm trying to fetch the top playlists from Apple Music using the charts API and I have the following code: func fetchPopularPlaylists() async throws -> [MusicItemCollection<Playlist>] {     var request = URLRequest(url: URL(string: "https://api.music.apple.com/v1/catalog/US/charts?types=playlists")!)     let userToken = try await fetchUserToken()     request.httpMethod = "GET"     request.addValue("Bearer \(Self.jwt)", forHTTPHeaderField: "Authorization")     request.addValue(userToken, forHTTPHeaderField: "Music-User-Token")     let dataRequest = MusicDataRequest(urlRequest: request)     let response = try await dataRequest.response()     let decoder = JSONDecoder()     let playlistResponse = try decoder.decode(MyChartsResponse.self, from: response.data)     return playlistResponse.results.playlists } And this code works well and as expected, I'm able to populate results. However, I believe that the response is getting decoded incorrectly. My response model object: struct MyChartsResponse: Codable {     struct Results: Codable {         let playlists: [MusicItemCollection<Playlist>]     }     let results: Results } The charts api however has the response listed in the form of: { "results": { "playlists": [ // playlist entities here ] } } This API response makes it seem like the proper Swift decoding structure is either struct MyChartsResponse: Codable {     struct Results: Codable {         let playlists: MusicItemCollection<Playlist>     }     let results: Results } or struct MyChartsResponse: Codable {     struct Results: Codable {         let playlists: [Playlist]     }     let results: Results } but instead the playlist property has to be Array<MusicItemCollection<Playlist>> in order to decode correctly with no custom decoding. The playlists property is incorrectly getting wrapped in an extraneous collection on decoding which makes extracting it difficult.
Asked Last updated
.
Post not yet marked as solved
11 Views

Get listing of public playlists for any Apple Music user Swift iOS

Hi there, I don't know if this is possible or not, so I'm asking here. I'd like to know if there is a way to get a list of an Apple Music public playlist via the Apple Music API. I don't think that Music Kit is an option here, as these users would not be Apple Music users, but, again, I'm not sure. The first stumbling block is that I can't seem to figure out how to get an Apple Music users ID or maybe their curator ID, if that's what is needed. Once I had that, I'm still not sure how to get that user's public playlists. Any help on this would be appreciated. Thanks!
Asked Last updated
.
Post not yet marked as solved
11 Views

Deep link to Apple Music library playlist from Swift (iOS) app

Hi there, The following code snippet will open Apple Music on an iOS device to a catalog playlist, using the globalId. if let url = URL(string: "music://music.apple.com/us/playlist/\(playlist!.attributes.playParams.globalId!)") {             await UIApplication.shared.open(url) What I'd like to do is open Apple Music using the standard ID, as I don't want to force users to make a playlist public in order to link to it from my app. This requires the above code to use a library link instead of a catalog link. I've tried various permutations of the url, but I can't seem to find the secret sauce. Any tips, would be most appreciated. Thanks!
Asked Last updated
.
Post not yet marked as solved
415 Views

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
Asked
by whatsong.
Last updated
.
Post not yet marked as solved
30 Views

Apple MusicKit Queue entry endtime not set

Hello, I have a question and I hope someone can help me out. I'm trying to build a view that will respond to changes in ApplicationMusicPlayer.shared.queue. it gets back the current entity(MusicPlayer.Queue.Entry) with a lot of information but the endtime property isn't set. how can I resolve this issue? Stap one Getting playlist information with all tracks from apple music         var request = MusicCatalogResourceRequest<Playlist>(matching: \.id, equalTo: playlist.musicID)         request.properties = [.tracks]         request.limit = 1;             if let tracks = try await request.response().items.first?.tracks {                 viewModel.tracks = tracks             } Step 2 Add tracks to Queue ApplicationMusicPlayer.shared.queue = ApplicationMusicPlayer.Queue(for: viewModel.tracks)`  try await ApplicationMusicPlayer.shared.play() Sep 3 Player Starts playing update the view with the current entry I will successfully get title, subtitle and artwork but not a endtime that I need for building a nice playback timer Kind regards, Reinier de la Parra
Asked Last updated
.
Post not yet marked as solved
54 Views

MusicKit business questions

Hi, Given yesterday's announcement of a new subscription I have some business/permissions questions about apps built on MusicKit. If this is not the place to ask them can you please direct me to where would be more appropriate. (1) When we test to see if someone has a subscription, is there any difference between a Voice subscription and a regular subscription? i.e. will we be able to query and vend any song in Apple Music if the user has a Voice sub the same way we can if they have an individual or family sub? (2) Can our app require that they have some sort of subscription or do we have to provide functionality even if they don't? (3) If I read the agreement correctly, we can't store music for offline listening but we can create and use a playlist in Music. Is there a way to prompt the user to download the music to this playlist? Thank you, Daniel
Asked Last updated
.
Post not yet marked as solved
488 Views

ERROR_FAILED_TO_VERIFY_JWT error when trying to link with Apple Music

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>
Asked Last updated
.
Post not yet marked as solved
93 Views

Updated song rating not syncing to Apple Music

Hello! I am updating a songs rating by sending the value of the rating to "https://api.music.apple.com/v1/me/ratings/songs/id". The call succeeds and I get a 200 status code response back. Also when I fetch the rating for the just updated song, the returned data is correct. Just FYI, the app is still in development. Though, when I check the rating in the Apple Music app, the values aren't updated. Only when I switch off the "Sync Library" option in the Settings and turn it back on, the changes are also reflected in Apple Music. On my Mac I have to relaunch the Music app to see the changes. Why does that happen?
Asked
by lbinsq.
Last updated
.
Post not yet marked as solved
55 Views

How to set up shuffle in SystemMusicPlayer.shared

// withArtist is Artist. let player = SystemMusicPlayer.shared player.queue = [withArtist.fullAlbums!.first!] player.state.shuffleMode = .songs try await player.play() I can't set the shuffle mode with the above code. I would like to know how to set it.
Asked
by shi-n.
Last updated
.
Post marked as solved
210 Views

How to start playback of System Music Player?

Hi all, I am trying to start the playback of the current queue in the system music player using: let player = SystemMusicPlayer.shared try await player.play() But there is no playback, what am I doing wrong? Please keep in mind that there are already songs in the queue. I am simply unable start the playback.
Asked Last updated
.
Post not yet marked as solved
91 Views

Playing Songs and Albums with MusicKit (Bug?)

Hi, I am trying to use MusicKit for playing a song or an album. I am using the following code for it: Tested on iPhone 11 Pro, iOS 15.0.1 @MainActor private func play<I: PlayableMusicItem>(_ item: I) async throws { let systemPlayer = SystemMusicPlayer.shared if !systemPlayer.isPreparedToPlay { try await systemPlayer.prepareToPlay() } let queue = systemPlayer.queue try await queue.insert(item, position: .afterCurrentEntry) try await systemPlayer.play() } Before I was using the "oldschool" way using the MusicPlayer framework as follows: @MainActor private func playOldschool(identifier: String) { let systemPlayer = MPMusicPlayerController.systemMusicPlayer if !systemPlayer.isPreparedToPlay { systemPlayer.prepareToPlay() } systemPlayer.setQueue(with: [identifier]) systemPlayer.play() } Both have been tested under the same conditions (permissions, same MusicSubscription), however the one using MusicKit does not seem to work well as try await systemPlayer.prepareToPlay() fails. If I remove the prepareForPlay code, it fails on play() with the same message and error as prepareForPlay. The logs show this: [SDKPlayback] prepareToPlay failed [no target descriptor] Error Domain=MPMusicPlayerControllerErrorDomain Code=1 "(null)" I could not find anything for that error domain and code 1, however prepareToPlay fails even in playOldschool, if I use the async variant of the function. At the moment I am staying with playOldschool, because that actually plays music. I wonder if I should file a radar for this or if there is any additional requirement for MusicKit that I haven't fulfilled causing it to fail. Any help is appreciated!
Asked Last updated
.
Post not yet marked as solved
136 Views

User Library Songs and ArtworkImage

What is the correct way to use the new ArtworkImage view with songs from the user's library? I'm fetching the songs using MPMediaQuery.songs, since I want the user's entire library, which provides MPMediaItems with an MPMediaItemArtwork. I can't see a way to get an Artwork for use with ArtworkImage from this. I could manually fetch the artwork by using a MusicCatalogResourceRequest for each song or I could (very slowly) fetch the user's library using MusicDataRequest with /v1/me/library/songs?include=catalog, but neither seem correct. (I could use MusicCatalogResourceRequest per album, which would reduce the requests, but I'd like to display track specific artwork when available (e.g. Brian Eno's Music for Installations)) Thank you
Asked
by tgt.
Last updated
.
Post not yet marked as solved
178 Views

MusicKit

I don't know why but when I go into MusicKit part on developer part on my app on Apple's website there is no spot to configure it. I saw online a lot of articles saying that you have to configure it to use MusicKit with an app. Is this a bug or something or do I need to do something to enable it? I just don't understand I added it into my app but I can't seem to get this to work for some reason I'm not sure why.
Asked
by ellj69.
Last updated
.
Post marked as solved
329 Views

MusicKit Requests & Localization

Hi 👋 I would like to retrieve Apple Music resources in a specific language. For example, I live in France, but my iPhone language is set to English (UK), unfortunately, it seems like MusicKit is always fetching resources in French (I guess it's the default language associated to my Apple Music account). I know it's possible to specify the language code through the URL (using the l query parameter), but I really would like to use MusicDataRequest as less as possible. Could you please consider adding a way to do this? Regards, Julien
Asked
by Tekikou.
Last updated
.