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

142 Posts
Sort by:
Post not yet marked as solved
1 Replies
85 Views
In SwiftUI there is a built-in component for displaying album artworks called Artwork but there is no equivalent for UIKit. My current approach is to use the .url() method to read image's URL and download the image or read it from the disk but the performance is much worse than it was previously with MPMediaItem's artworkImage method. let artworkQueue = DispatchQueue( label: "MusicKit-ArtworkQueue", qos: .default, attributes: .concurrent ) let artworkSemaphore = DispatchSemaphore(value: 5) extension Song { func artworkImage(for size: CGSize, completion: @escaping (UIImage?) -> Void) { artworkQueue.async { artworkSemaphore.wait() defer { artworkSemaphore.signal() } let imageURL = artwork?.url( width: Int(size.width), height: Int(size.height) ) // I hate doing this as it might very well break in the future guard let imageURL, imageURL.scheme == "musicKit" else { return completion(nil) } guard let imageData = try? Data(contentsOf: imageURL), let image = UIImage(data: imageData) else { return completion(nil) } completion(image) } } } I really dislike this approach because it feels hacky but somewhat works. You might ask what's the semaphore for? Well, without it I could notice that MusicKit was choking and after reading too many artworks at once. Can someone from Apple please provide us with an example on how to use MusicKit with UIKit properly? Ideally (IMO) we would have a method defined on Song and other MusicKit structures that returns the image for us, just like MPMediaItem had the .artwork() method. It would make our lives so much easier.
Posted
by wiencheck.
Last updated
.
Post not yet marked as solved
0 Replies
101 Views
Has anyone found a way to retrieve user token if I want to make an app on Flutter that uses that to make Apple Music API calls to just retrieve the user data and display it on the application? Something like when a user opens their app, there is a button that says connect with apple. It takes the user to give permissions for apple music and that retrieves their user token. I know there is Music Kit on Swift but i wonder if there is something like that on flutter
Posted
by jverma.
Last updated
.
Post not yet marked as solved
0 Replies
102 Views
We are looking at potentially adding access to Apple Music Classical into a game we have with classical music. I cannot find any documentation that states if MusicKit can access the subscription content on Apple Music Classical. We would prefer to give our players the option to play with the higher quality subscription music if desired. Thank you in advance for your assistance.
Posted
by StuartDig.
Last updated
.
Post not yet marked as solved
0 Replies
106 Views
I am trying to get the playbackStoreID via the MPMediaPickerController so I can play songs in my app. For many songs I can see and select I am getting a value of "0" for the playbackStoreID on the returned MPMediaItem. Now if I use the "Music" app I can play those songs, but since the playbackStoreID is "0" I cannot successful get them in the queue for a MPMusicPlayerController.applicationQueuePlayer What's the deal? How do I get a proper ID that I can use to get those songs played? If I cannot, how can I hide those songs from the MPMediaPickerController so a user does not think they can play those songs in my app?
Posted
by hotngui.
Last updated
.
Post not yet marked as solved
1 Replies
536 Views
Hi, Is there any reasonable way to use MusicKit on the Vision Pro simulator. I have been unable to get anything working and I was wondering if the situation is the same as iOS etc where you need a physical device to test the app.
Posted
by Superbro.
Last updated
.
Post not yet marked as solved
0 Replies
109 Views
Hi, is there a way to display the animated cover art in an app? Not every album has a cover art but for the ones that have one I would like to display them instead of the artwork. Thank you :)
Posted
by FPST.
Last updated
.
Post not yet marked as solved
6 Replies
3.8k 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 AppWriter.
Last updated
.
Post not yet marked as solved
0 Replies
166 Views
I need to duck the audio coming from ApplicationMusicPlayer while playing a local file using AVAudioPlayer. I've tried using the duckOthers option as follows, but it doesn't work: let appAudioSession = AVAudioSession.sharedInstance() do { try appAudioSession.setCategory(.playAndRecord, mode: .default, options: .duckOthers) Maybe this is because there's one session for the entire app, and ApplicationMusicPlayer is using it? This is a fairly critical problem for my application, since Music content is always much louder than locally recorded content. Any insight appreciated.
Posted Last updated
.
Post not yet marked as solved
0 Replies
249 Views
I filed FB13689023 for this since it is clearly unexpected. Non Apple Music library tracks are not returned on macOS using MusicLibraryRequest. I tried querying by artist where I only get Apple Music tracks, and by id where I don't get the track. On iPhone and iPad I was able to get both AM and non-AM tracks, that's how I got a valid id to try on macOS. Sync Library is on. The build targets My Mac (Designed for iPad). I'm using Xcode 15.3 and I'm on Sonoma (14.4). Any help is appreciated...
Posted
by gbuela.
Last updated
.
Post not yet marked as solved
1 Replies
244 Views
I'm trying to find a library item by title and artist but it returns 0 items. Example below for existing track in my library. With title filter commented out, it successfully gives me all library items for that artistName. If I add the title filter, or have only the title filter, I get 0 items. Why is that? var request = MusicLibraryRequest<MusicKit.Track>() // request.filter(matching: \.title, equalTo: "Crises (Remastered 2013)") request.filter(matching: \.artistName, equalTo: "Mike Oldfield") let response = try await request.response() I can find the track by filtering the returned tracks by artist, but I feel this might not be an ideal approach if I have a bunch of tracks to find, possibly by different artists. The reason I'm not querying by id is that I'm planning to do this sort of query for non Apple Music items and if I'm not mistaken there is no cross-device id for those (even with Sync Library on). If I have the app on multiple devices with the same Apple ID looking at the same library, I want device 2 to find the track you interacted with on device 1. If there are better ways to solve this, any ideas are welcome. Appreciate any help.
Posted
by gbuela.
Last updated
.
Post not yet marked as solved
0 Replies
206 Views
I was about to finally sign up for the Apple Music affiliate program since one of my apps does provide the MusickKit Subscription Offer. However, it looks like it was renamed and restricts usage to only artists and record labels. (https://partners.applemediaservices.com) Is this correct? Can I as an indie developer not earn commission of Apple Music that I drive from my apps?
Posted
by hotngui.
Last updated
.
Post not yet marked as solved
1 Replies
202 Views
After thoroughly scouring the internet numerous times, I came to the realization that Apple has not documented their User Authentication flow. Instead, developers are often directed to use their JavaScript solution, which proves to be insufficient and impractical for many projects. Could we please request a comprehensive documentation outlining the process of generating a Music User Token from the Developer Token? This would greatly benefit developers seeking to integrate Apple Music functionality into their projects.
Posted Last updated
.
Post not yet marked as solved
0 Replies
188 Views
Hello everyone, my name is Joshua Osagie. For 2 months now, I have been trying to build my own music application, but unfortunately, I can’t because I was thinking I would get an API from maybe Apple Music or Spotify that will grant me access to over 100 million music. Even if the API is paid for, I have been doing my research, but then it's kind of impossible. So please, if anyone has an idea on what I can do to bring this application to life, I will really appreciate it. Or if anyone could share me an idea on how to get over millions of music on my app, I will be really grateful.
Posted Last updated
.
Post not yet marked as solved
0 Replies
147 Views
I'm working on an application that aims to deliver a DJ-like experience by overlapping songs and implementing volume fading. During development, I've encountered a roadblock due to the MusicPlayerController singleton behavior in iOS, which seems to only support playback of one audio stream at a time and doesn't support overlapping of songs or fading volume between tracks. I understand that Apple Music content is protected and that playback through Apple MusicKit must respect the DRM and licensing agreements. However, I've noticed an application called "Mixonset" that seems to be able to stream songs from Apple Music, use the music player, and create an overlapping effect of songs for users. Could anyone share insights on how Mixonset might be achieving this within the constraints of the Apple MusicKit? Is there any approach that I could explore to implement similar functionality, such as overlapping songs or crossfading while adhering to Apple's guidelines and without violating any terms of service? Any advice or direction towards documentation and API capabilities that could support these features would be greatly appreciated. Thank you for your assistance.
Posted Last updated
.
Post not yet marked as solved
0 Replies
164 Views
Hi everyone! Are there any plans or existing alternatives to include the date a track was added to a playlist within Apple Music's API[1]? This functionality exists on Spotify[2] (with their "added_at" attribute), and it would be helpful for ordering tracks retrieved from playlists. Thank in advance for any help! [1]https://developer.apple.com/documentation/applemusicapi/get_a_catalog_playlist_s_relationship_directly_by_name [2]https://developer.spotify.com/documentation/web-api/reference/get-playlists-tracks
Posted
by x64Eddie.
Last updated
.
Post not yet marked as solved
0 Replies
238 Views
I often find when doing basic actions in MusicKit it is incredibly slow compared to Apple's Music App. I've tried different versions, devices, networks, Apple's sample code, it all throughout the last several years, and it is all the same. Does anyone else have this issue?
Posted Last updated
.
Post not yet marked as solved
7 Replies
2.9k Views
The MusicKit video states that you just enable "MusicKit" in your application identifier and "you're done!" Ok, so I did that, and I'm seeing the following error when trying to run a song query: [DataRequesting] Failed retrieving MusicKit tokens: Error Domain=ICErrorDomain Code=-8200 "Media API Token Service's response was invalid (status code: Unauthorized (401))." UserInfo={NSDebugDescription=Media API Token Service's response was invalid (status code: Unauthorized (401))., NSUnderlyingError=0x6000023a0c60 {Error Domain=AMSErrorDomain Code=301 "Invalid Status Code" UserInfo={NSLocalizedDescription=Invalid Status Code, AMSURL=https://sf-api-token-service.itunes.apple.com/apiToken?REDACTED, AMSStatusCode=401, AMSServerPayload={ status = verificationFailure; }, NSLocalizedFailureReason=The response has an invalid status code}}}. Throwing .developerTokenRequestFailed. Is this just broken on Apple's side? Is there some other magic string that needs to be added to the plist other than NSAppleMusicUsageDescription?
Posted
by xinsight.
Last updated
.
Post not yet marked as solved
0 Replies
207 Views
I can't seem to find an album using MusicKit containing RecordLabel. I am using album.with([..., .recordLabels, ...] but I only see an empty recordLabels collection returned for every album I am trying... Is this actually available / populated through MusicKit?
Posted
by ridmaur.
Last updated
.