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

141 Posts
Sort by:
Post not yet marked as solved
0 Replies
581 Views
Hey all, I was just wondering what would be the best/easiest way to have a sample for any MusicItem to use in SwiftUI previews. I know I could convert one into a string and then decode (as it conforms to Codable) but maybe there is a way that would make it easier to setup? if not I might file a feedback for this as I think it would be great if all MusicItem structures would have a .example or something like that so for a view you'd have #Preview { SongTitlesView(song: Song.example) }
Posted
by
Post not yet marked as solved
2 Replies
880 Views
Hi, My app hangs for about a second when I open the app when it's been in background phase. It doesn't hang every time, but it hangs randomly (like once in 10 times) when I open the app again. I am not able to reproduce what causes this hang. Hang Detection provides hang logs (spindump) when hang occurs. It has something to do with MusicKit as logs mention it but I cannot understand what it is. Please help me understand these logs. I am running iOS 17 beta 1 with MusicKit and ApplicationMusicPlayer. Heaviest stack for the main thread of the target process: 69 start + 2104 (dyld + 87288) [0x1b719b4f8] 69 ??? (Timed + 32864) [0x104ae8060] 69 ??? (SwiftUI + 980040) [0x19840a448] 69 ??? (SwiftUI + 1071088) [0x1984207f0] 69 ??? (SwiftUI + 1667804) [0x1984b22dc] 69 UIApplicationMain + 340 (UIKitCore + 3740336) [0x196c602b0] 69 -[UIApplication _run] + 888 (UIKitCore + 3741260) [0x196c6064c] 69 GSEventRunModal + 164 (GraphicsServices + 4644) [0x1d6199224] 69 CFRunLoopRunSpecific + 600 (CoreFoundation + 527792) [0x1947fedb0] 68 __CFRunLoopRun + 1996 (CoreFoundation + 509348) [0x1947fa5a4] 68 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 (CoreFoundation + 626340) [0x194816ea4] 68 _dispatch_main_queue_callback_4CF + 44 (libdispatch.dylib + 75296) [0x19c404620] 67 _dispatch_main_queue_drain + 744 (libdispatch.dylib + 76056) [0x19c404918] 67 swift_job_runImpl(swift::Job*, swift::ExecutorRef) + 72 (libswift_Concurrency.dylib + 274348) [0x19f58cfac] 67 swift::runJobInEstablishedExecutorContext(swift::Job*) + 416 (libswift_Concurrency.dylib + 269688) [0x19f58bd78] 66 ??? (MusicKit + 4857464) [0x208aabe78] 66 ??? (MusicKit + 4856108) [0x208aab92c] 66 -[MusicKit_SoftLinking_MPMusicPlayerController nowPlayingItem] + 24 (MusicKit + 157364) [0x2086306b4] 66 -[MPMusicPlayerController nowPlayingItem] + 24 (MediaPlayer + 1358540) [0x1a681bacc] 66 -[MPMusicPlayerController _nowPlaying] + 372 (MediaPlayer + 1329552) [0x1a6814990] 66 -[MPMusicPlayerController onServer:] + 52 (MediaPlayer + 1333428) [0x1a68158b4] 63 -[MPMusicPlayerApplicationController _establishConnectionIfNeeded] + 1768 (MediaPlayer + 1553848) [0x1a684b5b8] 63 _NSXPCDistantObjectSimpleMessageSend1 + 60 (Foundation + 208348) [0x1937daddc] 63 -[NSXPCConnection _sendSelector:withProxy:arg1:] + 116 (Foundation + 208548) [0x1937daea4] 62 -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:] + 2160 (Foundation + 214664) [0x1937dc688] 62 __NSXPCCONNECTION_IS_WAITING_FOR_A_SYNCHRONOUS_REPLY__ + 16 (Foundation + 652944) [0x193847690] 62 xpc_connection_send_message_with_reply_sync + 264 (libxpc.dylib + 67488) [0x1fc00d7a0] 62 dispatch_mach_send_with_result_and_wait_for_reply + 60 (libdispatch.dylib + 127760) [0x19c411310] 62 _dispatch_mach_send_and_wait_for_reply + 540 (libdispatch.dylib + 126832) [0x19c410f70] 62 mach_msg + 24 (libsystem_kernel.dylib + 4692) [0x1da082254] 62 mach_msg_overwrite + 436 (libsystem_kernel.dylib + 83544) [0x1da095658] 62 mach_msg2_trap + 8 (libsystem_kernel.dylib + 3332) [0x1da081d04] *62 ??? (<31E57057-A9A0-3BE5-90CB-5C08E9683B34> + 217132) [0xfffffff007e0102c] Thank you. CC @JoeKun
Posted
by
Post not yet marked as solved
0 Replies
520 Views
As of the latest builds of both iOS 16.6 and iOS 17.0, playing albums from a users library using ApplicationMusicPlayer plays the songs on that album out of order. This is a dealbreaker for my app, and I’ve had to revert back to the Media Player framework for reliable behavior. If I fetch an album from a MusicLibraryRequest and load it into the queue using the API introduced in 16.4, init(album:startingAt:)., it starts at track 1 but then plays the rest of the tracks in random order. This happens whether skipping tracks or letting them play through. The shuffleMode of the player is .off. The issue does not occur with albums fetched from the Apple Music catalog and loaded using that same API, nor does it occur for MPMediaItemCollections loaded into an applicationQueuePlayer via a queue descriptor. I've submitted this issue as FB12495051 and provided a sysdiagnose. Please let me know if I can provide any other information.
Posted
by
Post not yet marked as solved
1 Replies
531 Views
Hello Everyone, We've had an idea for a hardware controller for Logic X, and have already made prototypes that work with Garage Band and other applications. My question is - Does Apple have a development license available for Logic X? Thanks.
Posted
by
Post not yet marked as solved
0 Replies
389 Views
I'm currently working on integrating MusicKit into my app and would like to provide a seamless user experience by displaying only the songs that are available in the user's region or country. However, after going through the MusicKit documentation, I couldn't find a direct method to determine song availability based on the user's location. I wanted to inquire if there is a way to determine if a specific song or a catalog of songs is available in the user's region or country using MusicKit. It would be incredibly helpful if someone could guide me on how to achieve this or provide any insights on alternative approaches. Thank you in advance for your assistance!
Posted
by
Post not yet marked as solved
0 Replies
534 Views
If a user has only added one song from an album in its library, the library album endpoint (/me/library/albums) will return this album. It does not make sense because the user did not add the full album to its library, only one song. Note that the Apple Music app is doing the same in its Library > Albums section. How to retrieve only those albums which have been added ?
Posted
by
Post not yet marked as solved
0 Replies
415 Views
Planning to create a Music Game App similar to Guitar Hero kind of, and I am planning to use songs from beginner producers (They don't have any Publishers or Distributors). If I get their legal concent through a contract to use their songs, does Apple allow to have Music that is not from Itunes if I get the legal license from the producer to use their songs in my app? Will apple allow songs that don't have Publishers or Distributors, or in the App review stage they will flag it and cause an issue for me?
Posted
by
Post not yet marked as solved
1 Replies
628 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
Post not yet marked as solved
1 Replies
1.1k Views
I imported the MediaPlayer framework and used MPMusicPlayerPlayParameters in my SwiftUI project. While the app is launching, If the app is built by Xcode 14.3.1 or a newer version, it instantly crashes on a simulator or on a real device. This problem persists on iOS 16.0 to 16.4. (I haven't tried iOS 15 or below) I also tried to build and run the app with Xcode 15 - beta 4 however it still crashes. Because of this reason, I archive and submit to App Store with Xcode 14.2. (the built made by Xcode 14.2 works perfectly!!) Here is the error message: dyld[17235]: Symbol not found: _$sSo27MPMusicPlayerPlayParametersCSe05MediaB0Mc Referenced from: <77FEF170-9C51-3580-8F8B-2ADD2F1B3FD1> /Users/[UserName]/Library/Developer/CoreSimulator/Devices/72CE26D8-4DD4-4319-B0C7-DE52D6645875/data/Containers/Bundle/Application/C808623F-5372-40F0-907F-E86E12AE6EDD/[AppName].app/[AppName] Expected in: <06F636E1-695C-34F1-809D-7CA24F67AFE9> /Library/Developer/CoreSimulator/Volumes/iOS_20B72/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 16.1.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/MediaPlayer.framework/MediaPlayer I believe this is Apple related issue however if there is any way that can fix the issue, please let me know.
Posted
by
Post not yet marked as solved
0 Replies
559 Views
I have noticed changes Apple Music made to my library, take in particular a changed album edition that is reflected in how the title is listed. I can see the new title in the Music app in two different devices. On one device MPMediaQuery returns the album with the new title. The other device (an iPad with less memory, in case that matters) is still returning the old edition. Is there anything I can do to make sure the data returned is up to date and matches what is seen in the Music app?
Posted
by
Post not yet marked as solved
4 Replies
767 Views
I'm building a UIKit app that reads user's Apple Music library and displays it. In MusicKit there is the Artwork structure which I need to use to display artwork images in the app. Since I'm not using SwiftUI I cannot use the ArtworkImage view that is recommended way of displaying those images but the Artwork structure has a method that returns url for the image which can be used to read the image. The way I have it setup is really simple: extension MusicKit.Song { func imageURL(for cgSize: CGSize) -> URL? { return artwork?.url( width: Int(cgSize.width), height: Int(cgSize.height) ) } func localImage(for cgSize: CGSize) -> UIImage? { guard let url = imageURL(for: cgSize), url.scheme == "musicKit", let data = try? Data(contentsOf: url) else { return nil } return .init(data: data) } } Now, everytime I access .artwork property (so a lot of times) the main thread gets blocked and the console output gets bombared with messages like these: 2023-07-26 11:49:47.317195+0200 Plum[998:297199] [Artwork] Failed to create color analysis for artwork: <MPMediaLibraryArtwork: 0x289591590> with error; Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.mediaartworkd.xpc was invalidated: failed at lookup with error 159 - Sandbox restriction." UserInfo={NSDebugDescription=The connection to service named com.apple.mediaartworkd.xpc was invalidated: failed at lookup with error 159 - Sandbox restriction.} 2023-07-26 11:49:47.317262+0200 Plum[998:297199] [Artwork] Failed to create color analysis for artwork: file:///var/mobile/Media/iTunes_Control/iTunes/Artwork/Originals/4b/48d7b8d349d2de858413ae4561b6ba1b294dc7 2023-07-26 11:49:47.323099+0200 Plum[998:297013] [Plum] IIOImageWriteSession:121: cannot create: '/var/mobile/Media/iTunes_Control/iTunes/Artwork/Caches/320x320/4b/48d7b8d349d2de858413ae4561b6ba1b294dc7.sb-f9c7943d-6ciLNp'error = 1 (Operation not permitted) My guess is that the most performance-heavy task here is performing the color analysis for each artwork but IMO the property backgroundColor should not be a stored property if that's the case. I am not planning to use it anywhere and if so it should be a computed async property so it doesn't block the caller. I know I can move the call to a background thread and that fixes the issue of blocking main thread but still the loading times for each artwork are terribly slow and that impacts the UX. SwiftUI's ArtworkImage loads the artworks much quicker and without the errors so there must be a better way to do it.
Posted
by
Post not yet marked as solved
1 Replies
453 Views
Hi team, Are there any plans to update the Apple Music SDK for Android? With the upcoming release of the new music experience on iOS and the Apple Music app for Android getting a whole slew of features over the past month, is the (rather out of date - last update was December 2021) MusicKit SDK for Android going to get the new release that would enable developer avail of the new feature or is that SDK abandoned at this stage?
Posted
by
Post marked as solved
1 Replies
516 Views
Hello, I have an app published on AppStore which relies on MusicKit's functionality to retrieve results of MusicCatalogSearchRequest even when a user doesn't have an Apple Music subscription. (As per other sources and this thread, this is expected to work normally for users without the subscription.) The app used to work fine for months, yet today all the devices I tested on failed to execute the request (both AppStore and dev versions), resulting in the following log: 2023-07-27 23:45:16.036271+0200 Lisyn[6288:3156868] [DataRequesting] Updated user token cache with new error. 2023-07-27 23:45:16.043294+0200 Lisyn[6288:3156868] [DataRequesting] Failed retrieving user token: Error Domain=ICError Code=-8101 "Failed to fetch music user token with Unauthorized (401) status code. Account does not have an active Apple Music Subscription." UserInfo={NSDebugDescription=Failed to fetch music user token with Unauthorized (401) status code. Account does not have an active Apple Music Subscription.}. Throwing .userTokenRequestFailed. 2023-07-27 23:45:16.043413+0200 Lisyn[6288:3156868] [DataRequesting] Failed refreshing user token for MusicDataRequest.Context( url: "https://api.music.apple.com/v1/catalog/it/search?term=B&l=en-GB&types=songs&limit=25&omit%5Bresource%5D=autos", currentRetryCounts: [.userTokenInvalid: 1], activeRetryContext: RetryContext( reason: .userTokenInvalid, previousTokens: .personalizedTokens( developerToken: "some token", userToken: "some other token" ) ) ). Error = .userTokenRequestFailed. I am using automatic token generation and make requests via MusicKit: func searchMusic(searchText: String) async throws -> [PlaybackStoreID] { return try await throttler.schedule { var request = MusicCatalogSearchRequest(term: searchText, types: [Song.self]) request.limit = 25 return try await request.response().songs.map(\.id.rawValue) } } None of the certificate/identifier settings, nor the code related to the issue has been touched between when it was working and now. Also, live versions stopped working as well, so I am sure this isn't related. Is this a temporary issue? Should I roll out a fix using non-automatic token generation? Thank you!
Posted
by
Post not yet marked as solved
0 Replies
560 Views
For some reason when I go through the same process as shown here: https://developer.apple.com/documentation/musickitjs/ using MusicKit JS to authorize a user, the popup opens a user logs in and then on the access request screen you click allow nothing happens. You can see in the network tab when inspecting that the usertoken is being generated but the popup isn't closing and no matter what I try I cannot extract the usertoken, any thoughts?
Posted
by
Post not yet marked as solved
1 Replies
665 Views
Hi. In iOS 17 Apple introduced crossfading for the Music app. In my app I am using MPMusicPlayerController.applicationQueuePlayer and also want to support crossfading. In an early beta of iOS 17 my app crossfaded automatically with the same setting as for the Music app which maybe was a bug. However, I did not find any way to enable crossfade for my app. Does anybody know how to do that? Thanks, Dirk
Posted
by
Post not yet marked as solved
0 Replies
458 Views
I'm trying to pull library songs, playlist and artist from authorized user. The API gives me data in alphabetical order and there's no timestamp in the response, is it possible to fetch data with the most recent ones first? It is very difficult to pull all the data and filter ourselves, is it possible to fetch only the first 30-60 most recent ones?
Posted
by
Post not yet marked as solved
0 Replies
323 Views
Since I want to play music, I'd like to get notified when the user gets a valid apple music subscription. The way seems to be MusicSubscription.Updates but I can't figure out how to use it, and I can't find any code examples. Can anyone point to a code example of how it works? thanks
Posted
by
Post not yet marked as solved
1 Replies
433 Views
My app uses the voice synthesizer, and I'm trying to integrate apple music into my app using MusicKit to play a playlist during a workout. I want to lower the volume of the music while the synthesizer is speaking so the user can hear it. When I play music locally using AVAudioPlayer this is possible. I'm using the ApplicationMusicPlayer to play the tracks of the playlist. I don't see a way to lower the volume ApplicationMusicPlayer programmatically. Is there a way to programmatically change the volume of the ApplicationMusicPlayer? Or is there a better way to accomplish what I'm trying to do? thanks
Posted
by
Post not yet marked as solved
0 Replies
313 Views
Starting some time during the iOS 17 beta period, I've been seeing unusual playback rate behavior. I have an app that configures a queue of tracks to play and then sets the playback rate at the start of each new track, getting notified of each new track by observing MPMusicPlayerControllerNowPlayingItemDidChange. In iOS 17, I've noticed that setting the playback rate while an app is in the background will not actually change the playback rate. It appears to, and MusicPlayer.state.playbackRate returns the playback rate that has been requested, but the actual playback rate remains at whatever value it was previously. This is not the case when the app is in the foreground, setting the playback rate works as you would expect, updating the actual rate of playback as well as the value returned from the MusicPlayer. In iOS 16, these playback rate changes would occur normally, regardless of the state of the app in the foreground or background. Given the incorrect rate information coming back from the MusicPlayer state, this would appear to be an unexpected change. I've looked in the SDK diffs for any intentional changes for how playbackRate works and I haven't seen anything new or any new tech notes on the subject. Has anyone seen anything like this in their own implementations?
Posted
by