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
0 Replies
1 Views
The new MusicLibraryRequest<Playlist>() is great to get all the user's playlists but I have not found a way to exclude a specific type of playlist. For example; I wish to only get playlists that the user owns and can add content to (so this would exclude Smart and Curated playlists) I did find the Playlist.Kind enum, but I can't seem to apply this to the request, and it doesn't seem to have an option for smart playlists. So in short: Is there any way I can exclude Smart- and Curated Playlists from a MusicLibraryRequest
Posted Last updated
.
Post not yet marked as solved
0 Replies
34 Views
I'm developing an app which utilises playback from the Apple Music catalogue using MusicKit. Playback works fine however, whenever the playback state changes the ApplicationMusicPlayer.shared.state.objectWillChange publisher is fired twice. Moreover, with each emit the ApplicationMusicPlayer.shared.state is different. An example: Music is playing in my app. Music is paused. (Through any method of pausing) The objectWillChange publisher is called twice. In first call state is .playing In the second call state is .paused The same happens if playback is then resumed except the states switch. First, .paused and then .playing. I'm using Combine's .sink() method. I've checked for accidental duplicate subscriptions but there is only one. Is this the intended behaviour or is this an issue?
Posted Last updated
.
Post not yet marked as solved
1 Replies
63 Views
MusicPlayer.State supports shuffleMode and repeatMode, but there is no way to enable Autoplay. In the case of SystemMusicPlayer a user can enable AutoPlay from iOS Music app, but for ApplicationMusicPlayer, there's no way to offer Autoplay support. Additionally, when setting a new queue iOS Music app, disables Autoplay mode even if it was enabled before, but when using iOS Music app, the Autoplay stays enabled. I can understand that it may be intentional for some reason but doesn't seem user-friendly. Due to this, even when playing from Shortcuts app, Autoplay gets disabled, even though in most cases it shouldn't.
Posted
by addy239.
Last updated
.
Post not yet marked as solved
0 Replies
39 Views
Specifically, when the song is cut in the background, or when we open our APP after cutting the song through the music APP, the song cover built with ArtworkImage does not have any display, why is this? I have ensured that the artwork of the song is not nil and set the size, here is my application code: public func updateUI() {     coverImgView.subviews.forEach { $0.removeFromSuperview() }           let imageView = PlayerCoverImageView(artwork: artwork, size: size)     let viewCtl = UIHostingController(rootView: imageView)     viewCtl.view.frame = coverImgView.bounds     viewCtl.view.backgroundColor = .clear     coverImgView.addSubview(viewCtl.view)   } @available(iOS 15.0, *) struct PlayerCoverImageView: View {       var artwork: Artwork?   var size: CGSize       var body: some View {     if let artwork = artwork {       createCover(with: artwork)     } else {       EmptyView()     }   }       private func createCover(with artwork: Artwork) -> some View {     print("[*******] \(artwork), \(size)")     let width = size.width; let height = size.height     return ArtworkImage(artwork, width: width,               height: height)   } } console output: Artwork(   urlFormat: "musicKit://artwork/library/56D232E0-6CE5-40B5-92C3-CFEEC00D9CA6/{w}x{h}?at=item&mt=music&fat=https://is4-ssl.mzstatic.com/image/thumb/Music115/v4/45/8a/e4/458ae484-dc8b-5683-ce04-8d2948346462/JAY.jpg/1125x1229bb.jpg&id=6762479945777034135&fas=subscription&lid=56D232E0-6CE5-40B5-92C3-CFEEC00D9CA6",   maximumWidth: 0,   maximumHeight: 0 ) (307.0, 307.0)
Posted
by ArvinYang.
Last updated
.
Post not yet marked as solved
1 Replies
77 Views
Hi. I'm trying out some of the new MusicKit functionality using Xcode 14 beta 3 and macOS 13 beta 3 and I'm getting the above error (or similar) whenever I use any of the new classes with a Mac Catalyst destination (an iOS 16 destination works fine). I'm guessing one of my build settings is incorrect on either my project or target, but it's not obvious. So far I've set: Project / IOS Deployment Target = 16.0 Target / Minimum Deployments / iOS = 16.0 Could someone please tell me what I'm missing? Thanks in advance!
Posted
by dutton.
Last updated
.
Post not yet marked as solved
0 Replies
37 Views
In this thread it has been stated that getting artist artwork through the MusicKit api isn't allowed because of copyright issues. My question is: Is using the Apple Music REST api to get album artwork via the OpenGraph API also disallowed such that my app would be rejected? Wonder if I should pursue this option that I found or if I need to find another way? Seems like the answer would be no, but wanted to double check. Thanks for your response, this is my first app that I'm trying to publish to the store and I'd like to avoid getting an instant rejection for something like this. Code snippet: import MusicKit import Foundation import OpenGraph extension Artist {     func artwork(width: Int = 1024, height: Int = 1024) async -> URL? {         let id = self.id.rawValue         let countryCode = try? await MusicDataRequest.currentCountryCode         let url = URL(string: "https://music.apple.com/\(countryCode ?? "us")/artist/\(id)")!         return await withCheckedContinuation { continuation in             OpenGraph.fetch(url: url) { result in                 switch result {                     case .success(let og):                         let image = og[.image]?.resizeArtwork(width: width, height: height)                         if let image = image, let url = URL(string: image) {                             continuation.resume(returning: url)                         } else {                             continuation.resume(returning: nil)                         }                     case .failure(_):                         continuation.resume(returning: nil)                 }             }         }     } } extension String {     func resizeArtwork(width: Int, height: Int) -> String? {         do {             let regex = try NSRegularExpression(pattern: "/\\d+x\\d+cw", options: .caseInsensitive)             let newImage = regex.stringByReplacingMatches(in: self, options: [], range: NSRange(0..<self.utf16.count), withTemplate: "/\(width)x\(height)cc")             return newImage         } catch {             return nil         }     } }
Posted Last updated
.
Post not yet marked as solved
1 Replies
64 Views
I understand why there isn’t an API to remove items from the library or playlist, but I propose a way to safely remove items from the library or playlist which would show a system alert to confirm the removal. This is exactly how the deletion is allowed for the Photos Library via third-party apps.
Posted
by addy239.
Last updated
.
Post not yet marked as solved
3 Replies
162 Views
Hello, MusicPropertySource.catalog says it is available in the docs on macOS, but .library is not. Is that an oversight? How does this integrate with current uses of iTunesMusicLibrary framework and ITLibrary? Thank you, -- Greg Bolsinga
Posted
by Bolsinga.
Last updated
.
Post not yet marked as solved
3 Replies
211 Views
I am trying to follow along with this in order to auto generate my dev token on requests to MusicKit, but I am getting an error about by identifier, which was configured Link: https://developer.apple.com/documentation/musickit/using-automatic-token-generation-for-apple-music-api Error: 2022-04-26 14:12:06.353589-0400 [6885:431407] [DataRequesting] Failed retrieving developer token: Error Domain=ICErrorDomain Code=-8200 "Media API Token Service responded with status code: Not Found (404). This suggests that "<set_bundle_ID>" was likely not registered as a valid client identifier." UserInfo={NSDebugDescription=Media API Token Service responded with status code: Not Found (404). This suggests that "<set_bundle_ID>" was likely not registered as a valid client identifier., NSUnderlyingError=0x2827669a0 {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=404, AMSServerPayload={     message = "Client not found";     status = 40402; }, NSLocalizedFailureReason=The response has an invalid status code}}}. Throwing .developerTokenRequestFailed. error getting token
Posted Last updated
.
Post not yet marked as solved
0 Replies
44 Views
When working with embedded web content inside a native app, any calls to MusicKit.authorize will not be properly authenticate. Calling authenticate will open Safari, allow the user to login, then ask for user confirmation, but the window will not navigate back to the native app. Is it expected that developers would have to enable associated domains for the native app?
Posted Last updated
.
Post not yet marked as solved
0 Replies
49 Views
Android Music SDK Authentication always shows Install AppMusic App even though AppMusic App is already installed! when targetSdkVersion 29 works fine and shows links to Apple Music but using targetSdkVersion 30 always shows Install AppMusic App even though AppMusic App is already installed! Apple developer, please check this problem device : Pixel 6 Android os version : 12
Posted
by sdamn89.
Last updated
.
Post not yet marked as solved
6 Replies
302 Views
I've just begun to dip my toes into the iOS16 waters. One of the first things that I've attempted is to edit a library playlist using: try await MusicLibrary.shared.edit(targetPlaylist, items: tracksToAdd) Where targetPlaylist is of type MusicItemCollection<MusicKit.Playlist>.Element and tracksToAdd is of type [Track] The targetPlaylist was created, using new iOS16 way, here: let newPlaylist = try await MusicLibrary.shared.createPlaylist(name: name, description: description) tracksToAdd is derived by performing a MusicLibraryRequest on a specific playlist ID, and then doing something like this: if let tracksToAdd = try await playlist.with(.tracks).tracks {    // add tracks to target playlist } My problem is that when I perform attempt the edit, I am faced with a rather sad looking crash. libdispatch.dylib`dispatch_group_leave.cold.1:     0x10b43d62c <+0>:  mov    x8, #0x0     0x10b43d630 <+4>:  stp    x20, x21, [sp, #-0x10]!     0x10b43d634 <+8>:  adrp   x20, 6     0x10b43d638 <+12>: add    x20, x20, #0xfbf          ; "BUG IN CLIENT OF LIBDISPATCH: Unbalanced call to dispatch_group_leave()"     0x10b43d63c <+16>: adrp   x21, 40     0x10b43d640 <+20>: add    x21, x21, #0x260          ; gCRAnnotations     0x10b43d644 <+24>: str    x20, [x21, #0x8]     0x10b43d648 <+28>: str    x8, [x21, #0x38]     0x10b43d64c <+32>: ldp    x20, x21, [sp], #0x10 ->  0x10b43d650 <+36>: brk    #0x1 I assume that I must be doing something wrong, but I frankly have no idea how to troubleshoot this. Any help would be most appreciated. Thanks. @david-apple?
Posted Last updated
.
Post not yet marked as solved
3 Replies
408 Views
I noticed that MusicKit updated so that you do not need to create any JWT tokens anymore (it's automatic). But since it's automatic, how would I get the current user's recently played music? I know you can do it with the API, but how would you do it with MusicKit (assuming you have MusicKit setup and running properly already)? https://developer.apple.com/documentation/applemusicapi/get_recently_played_resources I've been looking through the MusicKit documentation and can't find a single reference to it. https://developer.apple.com/documentation/musickit
Posted
by bigdaddy1.
Last updated
.
Post not yet marked as solved
4 Replies
188 Views
I have been excitedly testing out MusicKit's new features to interact with a user's music library over the last couple of days. Albums and Songs are a much nicer paradigm than MPMediaItemCollection and MPMediaItem, but I'm afraid that there are some library-focused metadata options present on MPMediatem that are seemingly not currently exposed on Songs fetched from a MusicLibraryRequest that force me back into the world of MPMediaItems. A big component of my app is being able to sort and filter your library across properties like play count and date added. Am I right that these properties are not available when interacting with library Songs in MusicKit? dateAdded - The date the item was added to the library lastPlayTime - The date on which the item was last played playCount - The number of times the item has been played For as long as those properties are not available, I will need to dip back into MPMediaItems in order to continue offering important pieces of functionality in my app.  Those three are my highest priority for this area of MusicKit at this time, and are my biggest blockers on jumping into the new world as opposed to staying the old. I've submitted the above as FB10185523 While I'm at it, I also have a wishlist of some additional properties, only one of which is currently exposed on MPMediaItem. The rest of which correspond to metadata a user can set in Music.app on the desktop but have not historically been publicly exposed on MPMediaItem: isCloudItem - This is currently exposed on MPMediaItem and tells you whether an item is locally downloaded on the device. I understand that the includeOnlyDownloadedContent option can be set on a MusicLibraryRequest to return locally downloaded devices, but it would also be nice to have on a per-song basis to be able to display an indicator to the user.  startTime and stopTime - These properties correspond to the custom “start” and “stop” times a user can define for a song on the Options tab of Music.app on the desktop. These have not historically been exposed publicly. It would be nice to have access to these in order to be able to display an accurate play time if a user has customized it. sortAlbumTitle, sortAlbumArtist, sortArtist - These properties correspond to the “sort as” options a user can define for a song on the Sorting tab of Music.app on the desktop. These have not historically been exposed publicly. It would be nice to have access to these in order to display library items to a user in the order they’ve defined and expect, rather than ignore their preference.  I've submitted the above as FB10185575 Thanks!
Posted Last updated
.
Post not yet marked as solved
8 Replies
351 Views
I'm very excited about the new MusicLibrary API, but after a couple of days of playing around with it, I have to say that I find the implementation of filtering MusicLibraryRequests a little confusing. MPMediaQuery has a fairly extensive list of predicates that can be applied, including string and persistentID comparisons for artist, album artist genre, and more. It also lets you filter on an item’s title. MusicLibraryRequests let you filter on the item’s ID, or on its MusicKit Artist and Genre relationships. To me, this seems like it adds an extra step.  With an MPMediaQuery, if I wanted to fetch every album by a given artist, I’d apply an MPMediaPropertyPredicate looking at MPMediaItemPropertyAlbumArtist and compare the string. It was also easy to change the MPMediaPredicateComparison to .contains to match more widely. If I wanted to surface albums by “Aesop Rock” or “Aesop Rock & Blockhead,” I could use that. In the MusicLibraryRequest implementation, it looks like I need to perform a MusicLibraryRequest<Artist> first in order to get the Artist objects. There’s no filter for the name property, so if I don’t have their IDs, I’ve got to use filter(text:). From there, I can take the results of that request and apply them to my MusicLibraryRequest<Album> using the filter(matching:memberOf) function.  I could use filter(text:) on the MusicLibraryRequest<Album>, but that filters across multiple properties (title and artistName?) and is less precise than defining the actual property I want to match against. I think my ideal version of the MusicLibraryRequest API would offer something like filter(matching:equalTo:) or filter(matching:contains:) that worked off of KeyPaths rather than relationships. That seems more intuitive to me. I’m not saying we need every property from every filterable MPMediaItemProperty key, but I’d love to be able to do it on title, artistName, and other common metadata. That might look something like: filter(matching: \.title, contains: “Abbey Road”) filter(matching: \.artistName, equalTo: “Between The Buried And Me”) I noticed that filter(text:) is case insensitive, which is awesome, and something I’ve wanted for a long time in MPMediaPropertyPredicate. As a bonus, it would be great if a KeyPath based filter API supported a case sensitivity flag. This is less of a problem when dealing with Apple Music catalog content, but users’ libraries are a harsh environment, and you might have an artist “Between The Buried And Me” and one called “Between the Buried and Me.” It would be great to get albums from both with something like: filter(matching: \.artistName, equalTo: “Between The Buried And Me”, caseSensitive: false)  I've submitted the above as FB10185685. I also submitted another feedback this morning regarding filter(text:) and repeating text as FB10184823. My last wishlist item for this API (for the time being!) is exposing the MPMediaItemPropertyAlbumPersistentID as an available filter attribute. I know, I know… hear me out. If you take a look at the other thread I made today, you’ll see that due to missing metadata in MusicKit, I still have some use cases where I need to be able to reference an MPMediaItem and might need to fetch its containing MPMediaItemCollection to get at other tracks on the album. It would be nice to seamlessly be able to fetch the MPMediaItemCollection or the library Album using a shared identifier, especially when it comes to being able to play the album in MusicKit’s player rather than Media Player’s.  I've submitted that list bit as FB10185789 Thanks for bearing with my walls of text today. Keep up the great work!
Posted Last updated
.
Post not yet marked as solved
0 Replies
108 Views
Hello! I am currently working on a react.js application that is integrating with the MusicKit v3 library. I have followed the documentation to generate a JWT for MusicKit and add the library to my application. Using my token I am able to successfully retrieve song information from the Apple Music API, but I am having trouble with authentication. When I call music.authorize() and successfully go through the Apple sign in popup, I am receiving the following 403 error: https://play.itunes.apple.com/WebObjects/MZPlay.woa/wa/webPlayerLogout 403 musickit.js:44 Uncaught (in promise) AUTHORIZATION_ERROR: Unauthorized After stepping through the music kit API and login popup with breakpoints, I am seeing that the music user token is null, despite the login popup succeeding and returning a proper token/response: {"isAppleMusicSubscriber":"true","musicUserToken":"Ak4ItOgRRRG2y6xgA/OeWQPK0RqPQ/esAJkRN0B/Ua/AWLT52tLhd2TfzMK6uhH+Nczvd7wjYDM1UewG/NledKtimwlrR+s5tdQPk/FG28zqhBqXZ12q6LC516w8ELZDwv5T61kV8xiJ1KSO1q4pGi01JO7SuPMtOqB/QsycYj+xNnrYUEwlP5tm/zxfg7bWmvuWMwfUruYR+A1U9FdXZsdIITVmxCjiHg8ro9xXRzl6Txhsag\u003d\u003d","cid":"REDACTED","itre":"REDACTED","supported":"REDACTED"} I have tested my application with multiple Apple Music users who have paid subscriptions. All accounts are receiving this same error. I have tried regenerating my JWT token multiple times following various guides. My latest attempt used the following node library and parameters: var jwt = require('jsonwebtoken'); var fs = require('fs'); var privateKey = fs.readFileSync('./AuthKey_MYKEY.p8'); let now = new Date(); let nextMonth = new Date(now.getFullYear(), now.getMonth() + 1, now.getDate()); let nowEpoch = Math.round(now.getTime() / 1000); // number of seconds since Epoch, in UTC let nextMonthEpoch = Math.round(nextMonth.getTime() / 1000); // number of seconds since Epoch, in UTC var payload = {     iss: 'REDACTED', // TEAM ID     iat: nowEpoch,     exp: nextMonthEpoch }; var options = {     algorithm: 'ES256',     header: {         alg: 'ES256',         kid: 'REDACTED' // KEY ID     } }; jwt.sign(payload, privateKey, options, function(error, token) {     console.log(error);     console.log(token); }); I have a valid App Identifier created with the MusicKit App Service enabled. I am stuck! I have no other ideas on the possible root cause here. Is there something I am missing? I have a mobile app currently in Test Flight - does this app need to be released to the app store? I am out of guesses! Any support here would be greatly appreciated! Thank you for your time. Patrick
Posted Last updated
.
Post marked as solved
3 Replies
152 Views
When attempting to authenticate with the musickit-js v3, the page that gets loaded from authorize.music.apple.com results in an error "Cannot parse response" On the desktop, this does not happen. The authentication code in question is async login() { const mkInst = MusicKit.getInstance(); await mkInst.authorize(); } Not sure if this is limited to V3, as it's technically not officially released, but figured it was worth bringing to attention.
Posted Last updated
.
Post not yet marked as solved
0 Replies
57 Views
The supported Relationship Views for Albums in the API include appears-on, other-versions, related-albums, related-videos, but it doesn't support more-by-artist, this data is available when viewing the album in the Apple Music app and would be very useful if it was available in the Apple Music API and possibly MusicKit as well with new iOS update.
Posted
by addy239.
Last updated
.