Apple Music API

RSS for tag

Apple Music API integrates streaming music with Apple Music content.

Posts under Apple Music API tag

80 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Single Radio Station Lock Screen Audio Card
I am working on a radio app. This is the first time and I have a problem with lock Screen Audio Card. According to docs It looks ok but could you please check why I can not display Audio Now Playing Card on lock Screen. 2 Code samples, 1. Now Playing and 2. Logic of current song and Album art. 1. Now Playing // Create a dictionary to hold the now playing information var nowPlayingInfo: [String: Any] = [:] // Set the title of the current song nowPlayingInfo[MPMediaItemPropertyTitle] = currentSong // If album art URL is available, fetch the image asynchronously if let albumArtUrl = albumArtUrl { URLSession.shared.dataTask(with: albumArtUrl) { data, _, error in if let data = data, let image = UIImage(data: data) { // Create artwork object let artwork = MPMediaItemArtwork(boundsSize: image.size) { _ in image } // Update now playing info with artwork on the main queue DispatchQueue.main.async { nowPlayingInfo[MPMediaItemPropertyArtwork] = artwork MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo } } else { // If there's an error fetching the album art, set now playing info without artwork MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo print("Error retrieving album art data:", error?.localizedDescription ?? "Unknown error") } }.resume() } else { // If album art URL is not available, set now playing info without artwork MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo } } 2. Current Song, Album Art Logic let parts = currentSong.split(separator: "-", maxSplits: 1, omittingEmptySubsequences: true).map { $0.trimmingCharacters(in: .whitespaces) } let titleWithExtra = parts.count > 1 ? parts[1] : "" let title = titleWithExtra.components(separatedBy: " (").first ?? titleWithExtra return title } func updateSongInfo() { let url = URL(string: "https://live.heartfm.com.tr/listen/heart_fm/currentsong")! URLSession.shared.dataTask(with: url) { data, response, error in if let data = data, let songString = String(data: data, encoding: .utf8) { DispatchQueue.main.async { self.currentSong = songString.trimmingCharacters(in: .whitespacesAndNewlines) self.updateAlbumArtUrl(song: self.currentSong) } } }.resume() } private func updateAlbumArtUrl(song: String) { let parts = song.split(separator: "-", maxSplits: 1, omittingEmptySubsequences: true).map { $0.trimmingCharacters(in: .whitespaces) } let artist = parts.first ?? "" let titleWithExtra = parts.count > 1 ? parts[1] : "" let title = titleWithExtra.components(separatedBy: " (").first ?? titleWithExtra let artistAndTitle = artist.isEmpty || title.isEmpty ? song : "\(artist) - \(title)" let encodedArtistAndTitle = artistAndTitle.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? artistAndTitle albumArtUrl = URL(string: "https://www.heartfm.com.tr/ArtCover/\(encodedArtistAndTitle).jpg") }
0
0
420
Feb ’24
MusicKit album.isCompilation -- always false?
I can not find an album where isCompilation is true, even when the album clearly consists of "songs by various artists". For example: Album( id: "567979803", title: "Earth's Answer", artistName: "Brian Keane, Deuter, James Newton, ,...many more", isCompilation: false The compilation checkbox for this album in the Apple Music Catalog Get Info dialog is also not checked. Is this field NEVER SET in the catalog or the MusicKit API? If there IS an album where isCompilation is true, I'd like its ID to use for a test case. If not, can this be added to the API?
0
0
342
Feb ’24
MusicKit JS Native WebView Authorization Flow Not Initiating
The MusicKit JS V3 documentation has this article about Native WebViews. For some reason, my app fails to do anything after musicKitInstance.authorize() is called. I think that it is not being recognized as a WebView and is trying to open the window as if it was running in a browser, but since it's not a browser, there's no way for it to open a browser window. Is there something I can do to make this work? I have tried many things, including setting the user agent to a few different ones for web views and seeing if it behaves differently but didn't see any different behavior. Is there something musickit.js checks for, when determining if it's running in a WebView, that I can leverage to ensure the Native WebView workflow is followed?
0
0
336
Feb ’24
Using Music API previews in my app
I have an app that allows users to send messages to each other via a link. I'm receiving many requests from my users to add songs. Can I use the Apple Music API to add 30-second song previews along with the user's message? If users want to listen to the full song, there will be a link to the full song on Apple Music. My app contains ads and subscriptions.
0
0
302
Feb ’24
NSInternalInconsistencyException: No identifiers for model class: MPModelSong from source: (null)
My app is consistently crashing for a specific user on 14.3 (iMac (24-inch, M1, 2021) when their library is being retrieved in full. User says they have 36k+ songs in their library which includes purchased music. This is the code making the call: var request = MusicLibraryRequest<Album>() request.limit = 10000 let response = try await request.response() I’m aware of a similar (?) crash FB13094022 (https://forums.developer.apple.com/forums/thread/736717) that was claim fixed for 14.2. Not sure if this is a separate issue or linked. I’ve submitted new FB13573268 for it. CrashReporter Key: 0455323d871db6008623d9288ecee16c676248c6 Hardware Model: iMac21,1 Process: Music Flow Identifier: com.third.musicflow Version: 1.2 Role: Foreground OS Version: Mac OS 14.3 NSInternalInconsistencyException: No identifiers for model class: MPModelSong from source: (null) 0 CoreFoundation +0xf2530 __exceptionPreprocess 1 libobjc.A.dylib +0x19eb0 objc_exception_throw 2 Foundation +0x10f398 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] 3 MediaPlayer +0xd59f0 -[MPBaseEntityTranslator _objectForPropertySet:source:context:] 4 MediaPlayer +0xd574c -[MPBaseEntityTranslator _objectForRelationshipKey:propertySet:source:context:] 5 MediaPlayer +0xd5cd4 __63-[MPBaseEntityTranslator _objectForPropertySet:source:context:]_block_invoke_2 6 CoreFoundation +0x40428 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ 7 CoreFoundation +0x402f0 -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] 8 MediaPlayer +0xd5c1c __63-[MPBaseEntityTranslator _objectForPropertySet:source:context:]_block_invoke 9 MediaPlayer +0x11296c -[MPModelObject initWithIdentifiers:block:] 10 MediaPlayer +0xd593c -[MPBaseEntityTranslator _objectForPropertySet:source:context:] 11 MediaPlayer +0xd66c4 -[MPBaseEntityTranslator objectForPropertySet:source:context:] 12 MediaPlayer +0x1a7744 __47-[MPModeliTunesLibraryRequestOperation execute]_block_invoke 13 iTunesLibrary +0x16d84 0x1b4e1cd84 (0x1b4e1cd30 + 84) 14 CoreFoundation +0x5dec0 __invoking___ 15 CoreFoundation +0x5dd38 -[NSInvocation invoke] 16 Foundation +0x1e874 __NSXPCCONNECTION_IS_CALLING_OUT_TO_REPLY_BLOCK__ 17 Foundation +0x1cef4 -[NSXPCConnection _decodeAndInvokeReplyBlockWithEvent:sequence:replyInfo:] 18 Foundation +0x1c850 __88-[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:]_block_invoke_3 19 libxpc.dylib +0x10020 _xpc_connection_reply_callout 20 libxpc.dylib +0xff18 _xpc_connection_call_reply_async 21 libdispatch.dylib +0x398c _dispatch_client_callout3 22 libdispatch.dylib +0x21384 _dispatch_mach_msg_async_reply_invoke 23 libdispatch.dylib +0xad24 _dispatch_lane_serial_drain 24 libdispatch.dylib +0xba04 _dispatch_lane_invoke 25 libdispatch.dylib +0x16618 _dispatch_root_queue_drain_deferred_wlh 26 libdispatch.dylib +0x15e8c _dispatch_workloop_worker_thread 27 libsystem_pthread.dylib +0x3110 _pthread_wqthread 28 libsystem_pthread.dylib +0x1e2c start_wqthread
0
0
404
Feb ’24
MusicKit v3: CONTENT_RESTRICTED: Content restricted How do I fix?
Not sure when it happened but I can no longer play explicit songs in my app using MK v3. I've turned off restrictions/made sure i have access to explicit in... My phone (Screen Time) My computer (Screen Time) My iPad (Screen Time) music.apple.com (Settings) and I still get this error when I try to play a song in console. `CONTENT_RESTRICTED: Content restricted at set isRestricted (https://js-cdn.music.apple.com/musickit/v3/musickit.js:28:296791) at SerialPlaybackController._prepareQueue (https://js-cdn.music.apple.com/musickit/v3/musickit.js:28:318357) at SerialPlaybackController._prepareQueue (https://js-cdn.music.apple.com/musickit/v3/musickit.js:28:359408) at set queue (https://js-cdn.music.apple.com/musickit/v3/musickit.js:28:308934) at https://js-cdn.music.apple.com/musickit/v3/musickit.js:28:357429 at Generator.next (<anonymous>) at asyncGeneratorStep$j (https://js-cdn.music.apple.com/musickit/v3/musickit.js:28:351481) at _next (https://js-cdn.music.apple.com/musickit/v3/musickit.js:28:351708)`
0
0
377
Jan ’24
Apple Classical in CarPlay?
[posted January 30, 2024] Earlier this month, Apple Classical appeared as an app in CarPlay. Hallelujah!!! Three days later it disappeared after another update, apparently because all it did when activated via CarPlay was crash. OK, it was an oopsie (I get it. I spent 30 years in IT, and, well, it happens. They’re called “undocumented features”). Thing is: Apple hasn’t breathed a word about this event at all. Nothing. Nada. Zip. Zippo. Zilch. There’s a huge pent-up audience for this app in CarPlay. Is it coming? Please? Oh please oh please oh please?
0
0
619
Jan ’24
Apple Music API Open API 3.0 / Swagger spec?
Hi all! As the title states, I'm looking to integrate with Apple Music's REST API. I'm wondering if there are any OpenAPI 3.0 YAML or JSON specs available anywhere? I'd like to avoid transcribing the types found in the developer docs manually. Here's a link to the Apple Music API docs and to the OpenAPI 3.0 spec: https://developer.apple.com/documentation/applemusicapi https://spec.openapis.org/oas/latest.html Open API was previously known as "Swagger" too. Many thanks in advance!
0
0
370
Jan ’24
Access "About Artist" information and editorialNotes in general.
Is it possible using MusicKit API's to access the About information displayed on an artist page in Apple Music? I hoped Artist.editiorialNotes would give me the information but there is scarce information in there. Even for Taylor Swift, only editorialNotes.short displays brief info: "The genre-defying singer-songwriter is the voice of a generation." If currently not possible, are there plans for it in the future? Also, with the above in mind, and never seen any editorialNotes for a song, is it safe to assume editorialNotes are mainly used for albums?
0
0
336
Jan ’24
Is it possible to get an artistId from MusicKit just off the albumID
struct AlbumDetails : Hashable { let artistId: String? } func fetchAlbumDetails(upc: String) async throws -> AlbumDetails { let request = MusicCatalogResourceRequest<Album>(matching: \.upc, equalTo: upc) let response = try await request.response() guard let album = response.items.first else { throw NSError(domain: "AlbumNotFound", code: 0, userInfo: nil) } do { let artistID = try await fetchAlbumDetails(upc: upc) print("Artist ID: \(artistID)") } catch { print("Error fetching artist ID: \(error)") } return AlbumDetails(artistId: album.artists?.first?.id) with this function, i can return nearly everything except the artist ID so i know its not a problem with the request but I know there has to be a way to get the artistID, there has too. If anyone has a solution to this I would reallly appricate it
1
0
378
Jan ’24
Music User Token into Python via MusicKit JS or API?
Hi! I've been working on a project in python that pulls in a bunch of my personal apple music playback history and library, etc. I can't find a single good/functional example on how to pull the Music User Token via the android method or MusicKit JS (web) - I've spent a lot of hours on this today, and no permutation of existing examples/documentation has worked. Any guidance would be much appreciated!! If you have a web app that pulls the music user token, I just need help understanding how to get to the token itself. Thank you!
2
0
543
Jan ’24
Apple Music user token expiration
I'm writing an Android app that uses the Apple MusicKit SDK for Android. I am trying to understand how to handle the Apple Music user token, once I got it from authentication flow. I don't know when the token will expire, it is not a regular jwt token, so I cannot check the expiration date. And I don't want to run the auth flow on every app run, it will be annoying for the users. Any guidance on how to handle and invalidate apple music user tokens?
0
0
368
Jan ’24
Seeking Guidance on Creating a Playlist Navigation App with OAuth Authentication
Hello Apple Community, First, I'm asking this on the holidays, so happy holidays. Now I have some "fun coding time" and can do it because I have some holiday time. I'm new to this area and would greatly appreciate your expertise and guidance. Have mercy. I'm attempting to develop a simple application on my Mac OS to browse my playlists. However, I've encountered a few roadblocks that I struggle to navigate. I understand I need to implement two-factor authentication to access my playlists, for which an OAuth setup is required. This involves obtaining an Apple ID and a service ID and dealing with other complex elements. One particular challenge I'm facing is with the redirect URI in the OAuth process. It seems that it needs to be a valid domain, and I'm unsure if using a local server address like https://localhost:5000 would work. My goal is to create a basic Flask application that can interact with Apple's web authentication system, but I'm uncertain about the feasibility of this approach, given the domain restrictions. I would appreciate any advice or step-by-step guidance on the following points. What would be the simplest way to create an application (Swift, Python, or JavaScript) that can authenticate and enable browsing through my playlists? Any insights, tips, or examples you could share would be immensely helpful. I am eager to learn and look forward to your valuable suggestions. Anything step-by-step would be great, but I like to dream. Thank you so much for your time and assistance.
1
0
416
Jan ’24
Need to write a program to embed album art in purchased Apple Music
I recently downloaded Apple Music for for Windows 10 and started a new music library. Then I downloaded all my purchased music albums to my computer. However, the album art is not embedded in any of the m4a files. It is stored in a separate artwork folder. I have Visual Studio 2022 and was wondering how I might go about accessing the Apple Music app using the API. I want the script to go through all my purchased music and take the album art from the artwork folder and embed it in the purchased m4a files. I found some other programs/scripts online but they are all for iTunes or for Mac. None of the old scripts will work because they don’t recognize the new Apple Music for Windows music library. I can’t go back to iTunes because Apple removed all the music options from the iTunes for Windows app. Any ideas on how to get started writing the app/script would be greatly appreciated. Can I download something from Apple to make it easy to access the API in Visual Studio 2022 for Windows?
0
0
331
Dec ’23
SDK or API limitations/timeouts on 'unattended' use of an Apple Music-interface app
Hi, my team is developing an iOS app which connects to Apple Music (currently most of it is via API, but some tests have been done with MusicKit). In a separate development, we were using a service which competes with A.M., and when their (web) API is used, if the user doesn't interact with the app somehow (scrolling, buttons, etc), the connection will timeout after 30 seconds and force them to reconnect. So, questions I have are: Is there any timeout regarding stopping tracks in Apple Music or does the connection to the A.M. app stay active? If the connection drops on iOS as well, is there any limitation regarding streaming A.M. content via API (aka are there licensing issues as well?)
0
0
314
Dec ’23
Apple Music API Extended Features - UPDATE/DELETE
Trying to use the Apple Music API for mirroring playlists from spotify. Wondering if it will ever be on the roadmap to update/reorder playlists, or delete playlists/remove items using the API? Is this something that can't be handled or is it a business decision? I see that there is more flexibility with the MusicKit. Can we expect something like this in the future for the API? Thanks,
0
0
444
Dec ’23
Classical Music App metadata using API
Hi, I'm a newbie here. I've signed up for the developer program hoping to retrieve extended metadata for the Classical music that is avaliable in Classical app. For example, each performer is assigned an instrument or voice. Unfortunately, the test API call did not return extended metadata, just regular metadata from Music App or page. Does anybody knows if there are plans to make this extended metadata available thru API ?
0
0
291
Nov ’23