Post

Replies

Boosts

Views

Activity

How do you do a POST to a user's playlist so as to add tracks?
Trying to do what I can do pretty easily with a standard post request in a JS app, but now with Swift, and I'm struggling. I've tried with MusicRequestItem, but that fails, so I went with this and it responds with a 400. func addTracksToAppleMusicPlaylist(targetPlaylistId: String, tracksToSave: [Song]) async throws -> Void {     let tracks = tracksToSave.compactMap{         AppleMusicPlaylistPostRequest(id: $0.id, type: "songs")     }     do {         print("Saving tracks to Apple Music Playlist: \(targetPlaylistId)")         let tokens = try await self.getAppleMusicTokens()         if let url = URL(string: "https://api.music.apple.com/v1/me/library/playlists/\(targetPlaylistId)/tracks") {             var request = URLRequest(url: url)             request.httpMethod = "POST"             request.addValue("Bearer \(tokens.devToken)", forHTTPHeaderField: "Authorization")             request.addValue("\(tokens.userToken)", forHTTPHeaderField: "Music-User-Token")             request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")             let encoder = JSONEncoder()             let data = try encoder.encode(tracks)             request.httpBody = data             let session = URLSession(configuration: .default)             let task = session.dataTask(with: request) {(data, response, error) in                 if error == nil {                     if let httpResponse = response as? HTTPURLResponse {                         print("statusCode: \(httpResponse.statusCode)")                         print("response: \(httpResponse)")                     }                 } else {                     print("Error saving tracks to playlist \(String(describing: error))")                 }             }             task.resume()         } else {             print("Bad URL!")         }     } catch {         print("Error Saving Tracks to Playlist", error)         throw error     } }
1
0
898
Jul ’21
How to prevent macOS archive in Xcode Cloud build?
HI there, I just started using Xcode cloud. When building Xcode cloud, two archives are being generated: iOS and macOS. The macOS archive always errors out with: xcodebuild: error: Unable to find a destination matching the provided destination specifier: {generic:1, platform:macOS} I have no intention of my app running on macOS, but if I knew how to fix that, it might be kinda neat. But really, it's unnecessary, so how do I turn it off? Thanks, Kim
1
0
1.6k
Jul ’23
Delete song from playlist using Music Kit JS (or the API)?
I've got an app that allows a user to add songs to playlists in their library.I'd like to be able to delete songs as well, but it appears that there is no way to do this?It's baffling that this fundamental functionality is missing. Is there some super important reason that this is not possible? If so, what might that be?Are there plans to allow this functionality in the future?Thanks...
2
0
3.3k
Jun ’22
iOS 15 App Stops immediately after launch screen when using ipa
Hi there, I've started building an iOS app a couple months ago from scratch, using iOS 15 as the deployment target. I've finally gotten to the point where I'd like to have this tested in Test Flight, which I've done w/o issue with other apps. The problem and my confusion is around the fact that the app will run when my device (iPhone XS) is connected via USB and I run the app in Xcode, but when I run it after deployed via AppConnect and installed via Test Flight or when exported to ipa and imported via Apple Configurator 2, the app opens for an instant and then closes. No crash reports seem to be generated. The best I can seem to do is open the console on the device via Xcode, filter by Errors and Faults, and try to see what might be the problem. There's a couple things I see that make me think it's related to my problem. These two seem likely culprits: error 00:17:20.220010-0700 ReportCrash vm_read failed for task 14895, kr=4, start_address = 0x280c24180, end_address = 0x0 Scene FBSceneManager/sceneID:xyz.uniqeappname-default update failed: <NSError: 0x28385b960; domain: FBSceneErrorDomain; code: 1 (operation-failed); reason: "Scene update failed."> {   NSUnderlyingError = <NSError: 0x28243ff60; domain: FBWorkspaceScene; code: 1; reason: "Client process exited.">; } The thing is that I've googled the heck out of these, and can't find anything that might help me resolve the issue. Here's what I've tried (not all at the same time): Edit the scheme so that Run uses the Release build config. I thought this might make the app crash when running locally, but no. This has no effect when running the app locally via Xcode. The app still works as expected. Edit the scheme so that Archive uses the Debug configuration. I thought this might give more crash detail, but no effect. App still stops and there's no crash report. Setting the Optimization Level under Apple Clang - Code Generation from Fastest to None. I've read that this helps some folks. Selectively disabling parts of the app. I've read that certain things break the app when not running locally (e.g. deprecated UISearchDisplayController, which I'm not using). None of the above seem to have any effect at all, let alone toward resolving the issue. I'm using the following 5 packages in the app: Lottie Amplify SpotifyAPI (SpotifyWebAPI by Peter Schorn) KeychainAccess Firebase These add some additional dependencies. One of these, swift-nio-zlib-support, which is a dependency of Starscream, apparently, shows a couple warnings, not errors at build time. Amplify is the ios-sdk and used for auth and storage. Firebase is used for notifications and is configured in the AppDelegate. Notifications work when running via Xcode. This app also uses MusicKit iOS. Again, everything works when running via Xcode, which is baffling. Frankly, I'm at a loss as to how to troubleshoot this any further, so I'm hoping to get some help here. Thanks in advance for any advice toward resolving this issue.
2
0
8.5k
Nov ’21
Deep link to Apple Music library playlist from Swift (iOS) app
Hi there, The following code snippet will open Apple Music on an iOS device to a catalog playlist, using the globalId. if let url = URL(string: "music://music.apple.com/us/playlist/\(playlist!.attributes.playParams.globalId!)") {             await UIApplication.shared.open(url) What I'd like to do is open Apple Music using the standard ID, as I don't want to force users to make a playlist public in order to link to it from my app. This requires the above code to use a library link instead of a catalog link. I've tried various permutations of the url, but I can't seem to find the secret sauce. Any tips, would be most appreciated. Thanks!
2
0
3.3k
Nov ’21
Get listing of public playlists for any Apple Music user Swift iOS
Hi there, I don't know if this is possible or not, so I'm asking here. I'd like to know if there is a way to get a list of an Apple Music public playlist via the Apple Music API. I don't think that Music Kit is an option here, as these users would not be Apple Music users, but, again, I'm not sure. The first stumbling block is that I can't seem to figure out how to get an Apple Music users ID or maybe their curator ID, if that's what is needed. Once I had that, I'm still not sure how to get that user's public playlists. Any help on this would be appreciated. Thanks!
2
0
1.2k
Dec ’21
Missing play parameters when trying to play with MusicKit - potential storefront issue
I've got an iOS app build on Swift MusicKit that retrieves Apple Music tracks and presents them to a user in a list. Tapping the track attempts to the track using this function: func handlePlayThisTrack(track: AppleMusicTrack) async {   do {     let tracksToQueue = sortedTracks.compactMap{$0.track}     if let track = tracksToQueue.first(where: {$0.id.rawValue == track.id}) {       print("track", track)       player.queue = ApplicationMusicPlayer.Queue(for: tracksToQueue, startingAt: track )       try await player.play()     } else {       Logger.log(.error, "Track does not exist in sorted tracks!")     }   } catch {     print(error)   } } Sometimes, however, the track does not play, and checking the logs, I see the below. This only happens on some tracks, but on those that don't work it happens consistently. When printing the details for a track that doesn't work, it looks like this: track Track.song(Song(id: "1443100129", title: "She's Not There", artistName: "The Zombies")) And this looks like all the other tracks that do play. So I don't know where to look for said missing play parameters mentioned in the error. I have an inkling that this may have to do with the track not being available due to the country/storefront, and that the error message is misleading. I'm using the following to get the tracks: MusicCatalogResourceRequest<Song>(matching: \.isrc, equalTo: isrc) // <= the ISRC of the track I want to fetch My assumption is that the MusicCatalogResourceRequest would only respond with tracks in my country/storefront, but I think this may not be the case. Is there any way to create a MusicCatalogRequest in such a way that I only get results that are playable in my country/storefront? Any advice would be most appreciated. Thanks! 2022-02-25 02:24:56.971343+0700 MusicApp[19452:1186508] [Playback] Failed to insert MusicPlayer.Queue.Entry(id: "F6A04D56-F5C5-4628-B136-5438E188FDA5", transientItem: Track.song(Song(id: "1443100129", title: "She's Not There", artistName: "The Zombies"))) into queue descriptor because it's missing play parameters. 2022-02-25 02:24:57.102432+0700 MusicApp[19452:1186733] [Entitlements] MSVEntitlementUtilities - Process MusicApp PID[19452] - Group: (null) - Entitlement: com.apple.accounts.appleaccount.fullaccess - Entitled: NO - Error: (null) 2022-02-25 02:24:57.104579+0700 MusicApp[19452:1186733] [core] Attempted to register account monitor for types client is not authorized to access: {(   "com.apple.account.iTunesStore" )}
2
1
3.4k
Mar ’22
MusicCatalogSearchRequest does not find Albums that are found when using the Music app with the same search string
I am using the MusicKit library for Swift. With this: let searchString = “led zeppelin iv deluxe edition” var albumSearchRequest = MusicCatalogSearchRequest(term: searchString, types: [Album.self]) The response from: let response = try await albumSearchRequest.response() returns no albums; however searching manually for that exact string in the Music App on either iOS or macOS will return results. This is really weird and problematic if one is trying to search for albums or tracks specific to certain albums.
2
0
1.3k
Jun ’22
Get Songs from Apple Music API recently added
I'm working on an idea to use recently added tracks in my app. From what I can tell, the following endpoint will only supply albums and the id's are not related to any catalog resource: https://api.music.apple.com/v1/me/library/recently-added However, if I use the following endpoint, I get access to a semi-deeply-nested data value that contains the goodies I'm looking for: https://api.music.apple.com/v1/me/library/recently-added?include=catalog This seems better than doing a search for each item, as I have access to a catalog resource id. The data in the response is like the below. You can see under relationships, there's catalog, and in there is data, and in there is href, which is what I want. My problem is that I'm doing something dumb with the the decode. I'm using MusicKit's MusicDataRequest, as I don't see a way to get this info via MusicKit methods. And because of that, I gotta setup the request manually. If I just decode with the following, using Album as a type, the info I want isn't there for understood reasons. struct AppleMusicRecentlyAddedRequest: Decodable {   // var next: String?     var items: [Album]?     enum CodingKeys: String, CodingKey {         case next         case data     }     init (from decoder: Decoder) throws {         let container = try decoder.container(keyedBy: CodingKeys.self)         self.items = try container.decodeIfPresent([Album].self, forKey: .data)     } } I've attempted to go down the rabbit hole to get at catalog's data with: struct AppleMusicRecentlyAddedRequest: Decodable {     var items: [???]?        enum CodingKeys: String, CodingKey {         case next         case data         case relationships         case catalog     }     init (from decoder: Decoder) throws {         let container = try decoder.container(keyedBy: CodingKeys.self)         let dataContainer = try container.nestedContainer(keyedBy: CodingKeys.self, forKey: .data)         let relationshipsContainer = try dataContainer.nestedContainer(keyedBy: CodingKeys.self, forKey: .relationships)         let catalogContainer = try relationshipsContainer.nestedContainer(keyedBy: CodingKeys.self, forKey: .catalog)         self.items = try catalogContainer.decodeIfPresent([???].self, forKey: .data)     } } But anything I try for ???, including a complete manual copy of the response in a struct, isn't working, mainly because I'm not very good tat this. The main error I get is: Expected to decode Dictionary<String, Any> but found an array instead Which makes me think I gotta decode catalog data, or something, but I'm at my wits end at this point. Any tips on how to get at data would be awesome; even better would be just to the the href inside catalog/data for each item in the main response. @JoeKun, if there's anyway that MusicKit can make this easier, kindly advise. Thanks. [     {     "id":"l.WAiAqm3",     "type":"library-albums",     "href":"/v1/me/library/albums/l.WAiAqm3",     "attributes":{         "releaseDate":"2010-12-23",         "artwork":{             "width":1200,             "height":1200,             "url":"https://is4-ssl.mzstatic.com/image/thumb/Music/df/48/bb/mzi.wxowhcmy.jpg/{w}x{h}bb.jpg"         },         "dateAdded":"2022-04-13T07:07:50Z",         "name":"Play With Me Papa",         "artistName":"John Keawe",         "genreNames":[             "New Age"         ],         "playParams":{             "id":"l.WAiAqm3",             "kind":"album",             "isLibrary":true         },         "trackCount":1     },     "relationships":{         "catalog":{             "href":"/v1/me/library/albums/l.WAiAqm3/catalog",             "data":[                 {                     "id":"417478467",                     "type":"albums",                     "href":"/v1/catalog/us/albums/417478467",                     "attributes":{                         "artwork":{                             "width":600,                             "height":600,                             "url":"https://is4-ssl.mzstatic.com/image/thumb/Music/df/48/bb/mzi.wxowhcmy.jpg/{w}x{h}bb.jpg",                             "bgColor":"ecf2fe",                             "textColor1":"3a2212",                             "textColor2":"3f2b1b",                             "textColor3":"5e4b41",                             "textColor4":"615349"                         },                         "artistName":"John Keawe",                         "isSingle":false,                         "url":"https://music.apple.com/us/album/play-with-me-papa/417478467",                         "isComplete":true,                         "genreNames":[                             "New Age",                             "Music",                             "Worldwide"                         ],                         "trackCount":13,                         "isMasteredForItunes":false,                         "releaseDate":"2010-12-23",                         "name":"Play With Me Papa",                         "recordLabel":"Homestead Productions",                         "upc":"704565719925",                         "copyright":"℗ 2010 John Keawe",                         "playParams":{                             "id":"417478467",                             "kind":"album"                         },                         "isCompilation":false                     }                 }             ]         } ]
2
0
1.7k
May ’22
Music Kit HTML Embeds move an 490 px and below
Apple provides HTML Embeds for Music Kit JS, as mentioned here. There is a tool here that you can use to create embeds. Scroll to Preview Player. Now, if you set your browser width to less than 490 (right when the thumbnail gets smaller), the player will move vertically if you drag up. Not by much, it's hard to see without a contrasting background.. It's more noticeable in dark mode, as a white background shows clearly, like this: I'm misusing "drag" here: a simple, vertical scroll will cause this. Since this happens on Apple's own site, I'm fairly certain that this is not a "me problem," but who knows! Anyhow, I'm not sure if anyone has come across this. These embeds are pretty handy, and I'm loathe to roll my own player just to fix this. Any constructive advice would be appreciated.
2
0
543
Oct ’24
How to set volume with MusicKit Web?
I've got a web app built with MusicKit that displays a list of songs. I have player controls for play, pause, skip next, skip, previous, toggle shuffle and set repeat mode. All of these work by using music. The play button, when nothing is playing and nothing is in the queue, will enqueue all the tracks and start playing with the below, for example: await music.setQueue({ songs, startPlaying: true }); I've implemented a progress slider based on feedback from the "playbackProgressDidChange" listener. Now, how in the world can I set the volume? This seems like it should be simple, but I am at a complete loss here. The docs say: "The volume of audio playback, which is set directly on the HTMLMediaElement as the HTMLMediaElement.volume property. This value ranges between 0, which would be muting the audio, and 1, which would be the loudest possible." Given that all my controls work off the music instance, I don't understand how I can do that. In this video from WWDC 2022, music web components are touched on briefly. These are also documented very sparsely. The volume docs are here. For the life of me, I can't even get the volume web component to display in the UI. It appears that MusicKit Web is hobbled compared to the native implementation, but surely adjusting volume shouldn't be that hard right? I'd appreciate any insight on how to do this, including how to get web components to work (in a Next JS app). Thanks.
2
0
561
Jan ’25
MusicKit Web Playback States
In MusicKit Web the playback states are provided as numbers. For example the playbackStateDidChange event listener will return: {oldState: 2, state: 3, item:...} When the state changes from playing (2) to paused (3). Those are pretty easy to guess, but I'm having a hard time with some of the others: completed, ended, loading, none, paused, playing, seeking, stalled, stopped, waiting. I cannot find a mapping of states to numbers documented anywhere. I got the above states from an enum in a d.ts file that is often incorrect/incomplete. Can someone help out pointing to the docs or provide a mapping? Thanks.
2
0
398
Feb ’25
How to develop for impending beta features while supporting older iOS versions
Hi there, This is more of a "how-to," "am I doing this right?" question, as I've never done this before, and I couldn't find any definitive write up for how to do this, so I'm asking here. With the release of iOS16 beta, I've been implementing some new MusicKit features in an iOS app I'm working on that was initially built for iOS 15. Setup: dev machine: masOS Monterey 12.4 test device 1: iOS 15.4 test device 2: iOS 16 beta 2 Xcode versions: 14.0 beta 2 (14A5229c) 13.4.1 (13F100) The original app was written, using Xcode 13 and has an iOS Development Target of 15.0 Steps: create new branch off main called beta16 open Xcode beta2 and switch to new branch set the iOS Development Target for the project to 15.0 make code changes in the new branch, using ifavailable to handle both iOS 16 and fallback version code. Results: When I test the new code using Xcode 14 beta 2 on an iOS 16 device, things work as expected. When I test the new code using Xcode 14 beta on an iOS 15 device, the app builds and then crashes immediately upon open with: dyld[38909]: Symbol not found: _$s8MusicKit0A20CatalogSearchRequestV17includeTopResultsSbvs   Referenced from: /private/var/containers/Bundle/Application/4BB8F74F-FDA6-4DF1-8B04-010EA87BA80C/MyApp.app/MyApp   Expected in: /System/Library/Frameworks/MusicKit.framework/MusicKit Symbol not found: _$s8MusicKit0A20CatalogSearchRequestV17includeTopResultsSbvs   Referenced from: /private/var/containers/Bundle/Application/4BB8F74F-FDA6-4DF1-8B04-010EA87BA80C/MyApp.app/MyApp   Expected in: /System/Library/Frameworks/MusicKit.framework/MusicKit When coding, I followed all of Xcodes prompting that says when a potentially unsupported new feature is being used. When I look to where .includeTopResults is being used, I can see that it was not wrapped with ifavailable: var request = MusicCatalogSearchRequest(term: searchString, types: [Song.self])     request.includeTopResults = true let response = try await request.response() If I comment out the line with .includeTopResults, the app runs on the iOS 15 device w/o issue. If I wrap it in ifavailable, like this, it crashes as before: var request = MusicCatalogSearchRequest(term: searchString, types: [Song.self]) if #available(iOS 16, *) {     request.includeTopResults = true } let response = try await request.response() If I check the docs here, I think I'm using .includeTopResults correctly. Question: My main question here is if I'm correctly developing the app toward the goal of supporting new iOS 16 features, while also supporting devices using iOS 15, via fallback. Ultimately, I plan to merge the beta16 branch into a branch from which I'll deploy the app. The app crashing when using .includeTopResults has me hesitant because I don't know if that's a bug or if I'm the bug. Usually, it's the latter. It seems like the steps outlined above are the correct way to develop toward supporting upcoming features and "legacy iOS versions", but I'm not sure. Any clarity on this would be most appreciated. Thanks!
3
0
1.6k
Nov ’22
The Info.plist must contain a LSApplicationCategoryType key
I've created a Safari Extension app using the MultiPlanform option. I can successfully distribute the iOS app for beta testing with TestFlight, but when I try to do this with the macOS version, I get the following error: The product archive is invalid. The Info.plist must contain a LSApplicationCategoryType key, whose value is the UTI for a valid category. For more details, see "Submitting your Mac apps to the App Store". For the record, I searched for the mentioned document and couldn't find it. A link would be nice. Regardless, when I look at the macOS (App) in the Navigator Panel, there is no Info.plist file. There is one, however, in iOS (App). When I open Test Flight on my Mac, I see the app, but that's most likely because I have an M1 chip. I can't find any documentation on this, so I'm asking: Do I need to create an Info.plist file for the macOS (App), and if so, what do I need to put in there? If I don't need this, how do I deal with this error? Thanks in advance for any helpful advice.
3
0
6.3k
Sep ’23