MusicKit

RSS for tag

Let users play Apple Music and their local music library from your app or website using MusicKit.

MusicKit Documentation

Posts under MusicKit tag

107 results found
Sort by:
Post not yet marked as solved
26 Views

SIGABRT when running an app with MusicKit's ApplicationMusicPlayer.shared

Code I'm using (paraphrased) private let player = ApplicationMusicPlayer.shared private func play(songs : [Song]) {     Task.init {         player.setQueue(with: songs)         try await player.prepareToPlay()         player.play()     } } When I compile and run on my device (iOS 15 Beta 4), the app SIGABRT crashes on launch (does not hit breakpoints) with: dyld[9429]: Symbol not found: _$s8MusicKit0A6PlayerC4playyyFTj   Referenced from: /private/var/containers/Bundle/Application/21A3E366-FDC0-481C-B857-99353C8BED87/Soundbooth.app/Soundbooth   Expected in: /System/Library/Frameworks/MusicKit.framework/MusicKit Symbol not found: _$s8MusicKit0A6PlayerC4playyyFTj   Referenced from: /private/var/containers/Bundle/Application/21A3E366-FDC0-481C-B857-99353C8BED87/Soundbooth.app/Soundbooth   Expected in: /System/Library/Frameworks/MusicKit.framework/MusicKit Has anyone else seen this behavior?
Asked Last updated
.
Post not yet marked as solved
404 Views

[iOS 14 Bug?] MPMediaPlaylist.addItem(withProductID:) -> Freeze 🥶

Hello Apple World, I am working on an app that adds Apple Music songs to an MPMediaPlaylist. I was able to do this successfully in iOS 13.7. However, today I started testing on iOS 14.0.1 and the same code causes my app to freeze completely. print("PlaylistManager.addItem playlist \(playlist) identifier \(identifier) MPMediaLibrary.authorizationStatus() \(MPMediaLibrary.authorizationStatus().rawValue)") playlist.addItem(withProductID: identifier) { (error) in if error != nil {          print("An error occurred while adding an item to the playlist: \(error!.localizedDescription)") } } Output: "PlaylistManager.addItem playlist <MPConcreteMediaPlaylist: 0x2819dc4d0> identifier 1531532609 MPMediaLibrary.authorizationStatus() 3" Because I don't get any errors printed (the app just freezes up) and I don't see any crash logs in Devices and Simulators, I am not sure how to proceed. Is anyone else running into this issue with MPMediaPlaylist.addItem in iOS 14? Is there a general way to debug app freezes? Any help will be very much appreciated; Thank you in advance! Marvin
Asked Last updated
.
Post not yet marked as solved
37 Views

Upstream Service Error when using MusicDataRequest

Hey there! I'm trying to use MusicDataRequest to fetch the contents of a user's library. Most of the documented endpoints I've tried seem to be working as expected, but the /me/library/artists and /me/library/albums endpoints are consistenty giving me a 500 Upstream Service Error. Here's an example of my code, and the resulting error: let url = URL(string: "https://api.music.apple.com/v1/me/library/albums")! let request = MusicDataRequest(urlRequest: URLRequest(url: url)) do { let response = try await request.response()     let string = String(data: response.data, encoding: .utf8)!     print("success: \(string)") } catch {     print("error: \(error)") } MusicDataRequest.Error(   status: 500,   code: 50001,   title: "Upstream Service Error",   detailText: "Error fetching library content",   id: "5OFXMJAGNU2WCTDKNAYYP4BJXI",   originalResponse: MusicDataResponse(    data: 153 bytes,    urlResponse: <NSHTTPURLResponse: 0x0000000280f04dc0>   ) ) If I replace /albums with /songs or /playlists in the above code everything works as expected. Is there something I'm missing from the albums and artists requests? Or is this a bug with the API?
Asked
by benzgrant.
Last updated
.
Post not yet marked as solved
220 Views

Problem with applicationQueuePlayer Perform Method & Iterating Over Items

When using the applicationQueuePlayer perform(queueTransaction:completionHandler:) method, it takes multiple seconds to iterate over the items of either the MPMusicPlayerControllerMutableQueue or the MPMusicPlayerControllerQueue. While the iteration happens, the app is frozen (as this is done on the main thread) and I get the following error in console: ASYNC-WATCHDOG-1: Attempting to wake up the remote process I am dealing with a queue of a few hundred, but I don't believe the issue is with the number of MPMediaItems as when I get a similar number of items from e.g. MPMediaPlaylist, iterations happen instantly. Here is a simplified version of my code: var musicPlayerController = MPMusicPlayerController.applicationQueuePlayer self.musicPlayerController.perform { (currentQueue) in     return } completionHandler: { (newQueue, error) in     if let e = error {         print(e)     } else {         let items = newQueue.items         print("Starting iteration")         let tracks = items.map { Track(item: $0) }         print("Ending iteration")     } } In the console, I'll see "Starting iteration" printed in the console straight away as the method is called. And then I'll see "Ending iteration" multiple seconds later, during which the app is frozen. This method is called anytime the .MPMusicPlayerControllerQueueDidChange notification is posted.
Asked Last updated
.
Post not yet marked as solved
180 Views

MusicKit additional properties for Songs and Albums

Hi, I know MusicKit is in beta, but after having talked to an engineer at a WWDC lab, it seems to be feature complete for now. I really enjoy the framework and it helps wrap the Apple Music API nicely. However, the types it provides are missing some properties that are relevant to any music item (song, album, music video) such as the releaseDate, contentRating, durationInMillis and url. This is the JSON response from a /tracks relationship of an album: "previews": [ { "url": "https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview115/v4/e6/84/62/e6846266-2779-4527-902b-0a3b6f73be75/mzaf_18277320986443617976.plus.aac.p.m4a" } ], "artwork": { "width": 3000, "height": 3000, "url": "https://is1-ssl.mzstatic.com/image/thumb/Music124/v4/c4/7a/01/c47a01c2-2b04-a327-12bd-c726ae076c7f/886447823545.jpg/{w}x{h}bb.jpeg", "bgColor": "1c1c1c", "textColor1": "fafafa", "textColor2": "e1e1e1", "textColor3": "cdcdcd", "textColor4": "b9b9b9" }, "artistName": "Kollegah", "url": "https://music.apple.com/de/album/alpha/1477896577?i=1477896820", "discNumber": 1, "genreNames": [ "Hip-Hop/Rap", "Musik" ], "durationInMillis": 141827, "releaseDate": "2014-05-09", "name": "Alpha", "isrc": "DEDG61400001", "hasLyrics": true, "albumName": "King", "playParams": { "id": "1477896820", "kind": "song" }, "trackNumber": 1, "composerName": "Kai Engelmann, Phillip Herwig, Alexis Papadimitriou, Daniel Coros, Yunus Cimen & Sadik Kalyon", "contentRating": "explicit" } As you can see, the releaseDate, durationInMillis, url, contentRating, etc. are missing from the struct Song : MusicItem in the MusicKit. I was wondering if we can extend MusicKit as developers in a way to include the releaseDate and other types or are we making a choice between using custom models and custom requests vs. using MusicKit? Thanks
Asked Last updated
.
Post not yet marked as solved
219 Views

Can you get an Album from a Song with MusicKit?

Is it possible to get an album from a song in MusicKit? I haven't been able to find a way to do so currently. I have tried using .with() but it appears that album is not supported. What I am looking for is properties on the Song like what is present on MPMediaItem such as albumTitle, genre, etc.
Asked
by jknlsn.
Last updated
.
Post not yet marked as solved
207 Views

MPMusicPlayerController play user playlist (library playlist)

I am finding it impossible to play a library playlist using the MPMusicPlayerController class. I can play catalog playlists without any issues, but and user library specific playlist or song fails with "failed to prepare for play".  MPMusicPlayerController.applicationMusicPlayer.setQueue(with: [playlistId]) MPMusicPlayerController.applicationMusicPlayer.play() The above works so easily for playlists retrieved with: https://api.music.apple.com/v1/catalog/au/playlists. When trying to play a playlist from https://api.music.apple.com/v1/me/library/playlists it fails. Any ideas?
Asked Last updated
.
Post marked as solved
131 Views

Get Now Playing item in MusicPlayer

I cannot find any way to get Now Playing item in ApplicationMusicPlayer or SystemMusicPlayer. Is there any way to get it? If not, please consider adding a property to access the now playing item. I have also filed a feedback regarding this. FB9192603 Thank you
Asked
by RahulRS .
Last updated
.
Post not yet marked as solved
95 Views

Get queue and current item from ApplicationMusicPlayer?

I'd like to be able to monitor what is queued and what is currently playing in MusicKit's ApplicationMusicPlayer. Use cases: Show a "playing" indicator on the current track in a list. Show a "now playing" bar with song title, album, and artist. Is this possible?
Asked Last updated
.
Post marked as solved
103 Views

Song duration with MusicKit

I want to use the ApplicationMusicPlayer in my SwiftUI App and need the song duration to build a progression bar. ApplicationMusicPlayer only provides currentPlaybackTime and the Song struct in MusicKit has no duration prop. Is there an easy way to get the song duration with MusicKit or do I have to use a separate Apple Music API request to get durationInMillis?
Asked Last updated
.
Post not yet marked as solved
55 Views

MusicAlbums simulator recommendation

Hi, MusicKit is a particularly good example for teaching aspects of async coding. The API does many things very nicely. It would be nice if developers could access their Music libraries in the simulator as that would make this API a great teaching tool. Requiring new devs to deploy an app to a device in a workshop is a bit much for some. I have no idea if this is something you can practically enable - but I thought it was worth suggesting. Thanks, Daniel
Asked Last updated
.
Post marked as solved
221 Views

How can add songs to a playlist or create a new playlist from my APP?

Hi, I would like to be able to create a playlist from my app or add songs to an existing selected playlist in the user music library, How can I do that ? Is there an API in MusicKit to do that? The Shazam app is doing something similar with the My Shazam Songs playlist... Thanks
Asked
by aleroot.
Last updated
.
Post marked as solved
106 Views

Adding tracks to User's Library Playlist

Hi there, I'm creating an iOS 15 app, using the new Swift MusicKit beta. I've got basic "arbitrary" GET calls working with MusicDataRequest, like: fetch playlists and tracks. However, I cannot find good docs for adding tracks to a playlist in a user's library. I guess I could do this the "old way", but then I don't get the super-nice feature of auto dev/user tokens. So the question is: how to a POST, instead of GET in the following: let url = URL(string: "https://api.music.apple.com/v1/me/library/playlists/`\(targetPlaylistId)/tracks") let dataRequest = MusicDataRequest(urlRequest: URLRequest(url: url))
Asked Last updated
.
Post not yet marked as solved
91 Views

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     } }
Asked Last updated
.