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

206 Posts
Sort 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
7 Replies
1.3k Views
I have an application that as part of it's functionality, reproduce music from the music library using the AVPlayerItem. it's working fine on iOS but on the Macbook with M1 processor the audio is not loading. Plist already contains the items: NSAppleMusicUsageDescription & NSAppTransportSecurity
Posted
by
Post not yet marked as solved
1 Replies
383 Views
I have MusicKit integrated into an Android app and it works fine for most users, but some users report that it seems to successfully authenticate but it doesn't play their music. Logs from their devices show errors like this during MediaPlayerController configuration: log D/SVAudioRendererNative: FootHillConfig::config() id: 0123456789abcde E/SVAudioRendererNative: KDSetAndroidID() ERROR status: 4294924646 I omitted the id value in the config log, but the number of characters is accurate - 15 in the logs from problem devices, while I've noticed that logs from test devices seem to have 16 character ids in this log entry. Throughout the time that MediaPlayerController is active (and should be playing music), this log is continually seen: log E/SVAudioRendererNative: SVFootHillPExchange::SVFootHillPExchange() ERROR 4294924645 retrieving SPC I haven't seen any other errors propagating to the Java level or being logged. What can I do to solve this issue for our users?
Posted
by
Post not yet marked as solved
5 Replies
662 Views
When using the applicationQueuePlayer perform(queueTransaction:completionHandler:) method, it takes multiple seconds to iterate over the items of either the MPMusicPlayerControllerMutableQueue or the MPMusicPlayerControllerQueue. While the iteration happens, the app is frozen (as this is done on the main thread) and I get the following error in console: ASYNC-WATCHDOG-1: Attempting to wake up the remote process I am dealing with a queue of a few hundred, but I don't believe the issue is with the number of MPMediaItems as when I get a similar number of items from e.g. MPMediaPlaylist, iterations happen instantly. Here is a simplified version of my code: var musicPlayerController = MPMusicPlayerController.applicationQueuePlayer self.musicPlayerController.perform { (currentQueue) in     return } completionHandler: { (newQueue, error) in     if let e = error {         print(e)     } else {         let items = newQueue.items         print("Starting iteration")         let tracks = items.map { Track(item: $0) }         print("Ending iteration")     } } In the console, I'll see "Starting iteration" printed in the console straight away as the method is called. And then I'll see "Ending iteration" multiple seconds later, during which the app is frozen. This method is called anytime the .MPMusicPlayerControllerQueueDidChange notification is posted.
Posted
by
Post not yet marked as solved
3 Replies
1.2k Views
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?
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 not yet marked as solved
3 Replies
767 Views
Is it possible to get an album from a song in MusicKit? I haven't been able to find a way to do so currently. I have tried using .with() but it appears that album is not supported. What I am looking for is properties on the Song like what is present on MPMediaItem such as albumTitle, genre, etc.
Posted
by
Post marked as solved
2 Replies
443 Views
I cannot find any way to get Now Playing item in ApplicationMusicPlayer or SystemMusicPlayer. Is there any way to get it? If not, please consider adding a property to access the now playing item. I have also filed a feedback regarding this. FB9192603 Thank you
Posted
by
Post marked as solved
2 Replies
625 Views
Hi, I know MusicKit is in beta, but after having talked to an engineer at a WWDC lab, it seems to be feature complete for now. I really enjoy the framework and it helps wrap the Apple Music API nicely. However, the types it provides are missing some properties that are relevant to any music item (song, album, music video) such as the releaseDate, contentRating, durationInMillis and url. This is the JSON response from a /tracks relationship of an album: "previews": [ { "url": "https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview115/v4/e6/84/62/e6846266-2779-4527-902b-0a3b6f73be75/mzaf_18277320986443617976.plus.aac.p.m4a" } ], "artwork": { "width": 3000, "height": 3000, "url": "https://is1-ssl.mzstatic.com/image/thumb/Music124/v4/c4/7a/01/c47a01c2-2b04-a327-12bd-c726ae076c7f/886447823545.jpg/{w}x{h}bb.jpeg", "bgColor": "1c1c1c", "textColor1": "fafafa", "textColor2": "e1e1e1", "textColor3": "cdcdcd", "textColor4": "b9b9b9" }, "artistName": "Kollegah", "url": "https://music.apple.com/de/album/alpha/1477896577?i=1477896820", "discNumber": 1, "genreNames": [ "Hip-Hop/Rap", "Musik" ], "durationInMillis": 141827, "releaseDate": "2014-05-09", "name": "Alpha", "isrc": "DEDG61400001", "hasLyrics": true, "albumName": "King", "playParams": { "id": "1477896820", "kind": "song" }, "trackNumber": 1, "composerName": "Kai Engelmann, Phillip Herwig, Alexis Papadimitriou, Daniel Coros, Yunus Cimen & Sadik Kalyon", "contentRating": "explicit" } As you can see, the releaseDate, durationInMillis, url, contentRating, etc. are missing from the struct Song : MusicItem in the MusicKit. I was wondering if we can extend MusicKit as developers in a way to include the releaseDate and other types or are we making a choice between using custom models and custom requests vs. using MusicKit? Thanks
Posted
by
Post not yet marked as solved
2 Replies
419 Views
I'd like to be able to monitor what is queued and what is currently playing in MusicKit's ApplicationMusicPlayer. Use cases: Show a "playing" indicator on the current track in a list. Show a "now playing" bar with song title, album, and artist. Is this possible?
Posted
by
Post marked as solved
5 Replies
948 Views
Hello, I was trying to use the new ApplicationMusicPlayerController with an album from the music library. In my test code I am searching for the artist "LUWTEN" in my personal library. In my personal library there are two albums that will be found. When I try to play the first album I will get the error MSVEntitlementUtilities - Process .. PID[648] - Group: com.apple.private.tcc.allow - Entitlement: kTCCServiceMediaLibrary - Entitled: NO - Error: (null). Is there a way to play library music with the new ApplicationMusicPlayerController?     func searchLuwten () {         struct MyAlbums : Codable {             let results : Result         }                  struct Result : Codable {             let libraryAlbums : Albums             enum CodingKeys: String, CodingKey {                 case libraryAlbums = "library-albums"             }         }         struct Albums : Codable {             let href : String             let data : [LibraryAlbum]         }                  struct LibraryAlbum : Codable, PlayableMusicItem {             let id : MusicItemID             let attributes : Attributes                          var playParameters: PlayParameters? {                 attributes.playParams             }         }                  struct Attributes : Codable {             let name : String             let playParams : PlayParameters         }                  detach {             let term = "LUWTEN"             var components = URLComponents()             components.scheme = "https"             components.host   = "api.music.apple.com"             components.path   = "/v1/me/library/search"             components.queryItems =  [                 URLQueryItem (name: "term", value: term),                 URLQueryItem (name: "types", value: "library-albums")             ]                          guard let url = components.url else {                 return             }                          let dataRequest = MusicDataRequest(urlRequest: URLRequest(url: url))             let dataResponse = try await dataRequest.response()                          let decoder = JSONDecoder()             let albumResponse = try decoder.decode (MyAlbums.self, from: dataResponse.data)             let player = ApplicationMusicPlayer.shared             player.setQueue (with: albumResponse.results.libraryAlbums.data[0])             player.play()                      }     }
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 marked as solved
2 Replies
484 Views
I want to use the ApplicationMusicPlayer in my SwiftUI App and need the song duration to build a progression bar. ApplicationMusicPlayer only provides currentPlaybackTime and the Song struct in MusicKit has no duration prop. Is there an easy way to get the song duration with MusicKit or do I have to use a separate Apple Music API request to get durationInMillis?
Posted
by
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
by
Post not yet marked as solved
1 Replies
434 Views
Hi, MusicKit is a particularly good example for teaching aspects of async coding. The API does many things very nicely. It would be nice if developers could access their Music libraries in the simulator as that would make this API a great teaching tool. Requiring new devs to deploy an app to a device in a workshop is a bit much for some. I have no idea if this is something you can practically enable - but I thought it was worth suggesting. Thanks, Daniel
Posted
by
Post not yet marked as solved
8 Replies
1.1k Views
Hey there! I'm trying to use MusicDataRequest to fetch the contents of a user's library. Most of the documented endpoints I've tried seem to be working as expected, but the /me/library/artists and /me/library/albums endpoints are consistenty giving me a 500 Upstream Service Error. Here's an example of my code, and the resulting error: let url = URL(string: "https://api.music.apple.com/v1/me/library/albums")! let request = MusicDataRequest(urlRequest: URLRequest(url: url)) do { let response = try await request.response()     let string = String(data: response.data, encoding: .utf8)!     print("success: \(string)") } catch {     print("error: \(error)") } MusicDataRequest.Error(   status: 500,   code: 50001,   title: "Upstream Service Error",   detailText: "Error fetching library content",   id: "5OFXMJAGNU2WCTDKNAYYP4BJXI",   originalResponse: MusicDataResponse(    data: 153 bytes,    urlResponse: <NSHTTPURLResponse: 0x0000000280f04dc0>   ) ) If I replace /albums with /songs or /playlists in the above code everything works as expected. Is there something I'm missing from the albums and artists requests? Or is this a bug with the API?
Posted
by