Play songs from library

Hello,

I was trying to use the new ApplicationMusicPlayerController with an album from the music library. In my test code I am searching for the artist "LUWTEN" in my personal library. In my personal library there are two albums that will be found. When I try to play the first album I will get the error MSVEntitlementUtilities - Process .. PID[648] - Group: com.apple.private.tcc.allow - Entitlement: kTCCServiceMediaLibrary - Entitled: NO - Error: (null). Is there a way to play library music with the new ApplicationMusicPlayerController?


    func searchLuwten () {

        struct MyAlbums : Codable {

            let results : Result

        }

        

        struct Result : Codable {

            let libraryAlbums : Albums

            enum CodingKeys: String, CodingKey {

                case libraryAlbums = "library-albums"

            }

        }

        struct Albums : Codable {

            let href : String

            let data : [LibraryAlbum]

        }

        

        struct LibraryAlbum : Codable, PlayableMusicItem {

            let id : MusicItemID

            let attributes : Attributes

            

            var playParameters: PlayParameters? {

                attributes.playParams

            }

        }

        

        struct Attributes : Codable {

            let name : String

            let playParams : PlayParameters

        }

        

        detach {

            let term = "LUWTEN"

            var components = URLComponents()

            components.scheme = "https"

            components.host   = "api.music.apple.com"

            components.path   = "/v1/me/library/search"

            components.queryItems =  [

                URLQueryItem (name: "term", value: term),

                URLQueryItem (name: "types", value: "library-albums")

            ]

            

            guard let url = components.url else {

                return

            }

            



            let dataRequest = MusicDataRequest(urlRequest: URLRequest(url: url))

            let dataResponse = try await dataRequest.response()

            

            let decoder = JSONDecoder()



            let albumResponse = try decoder.decode (MyAlbums.self, from: dataResponse.data)



            let player = ApplicationMusicPlayer.shared

            player.setQueue (with: albumResponse.results.libraryAlbums.data[0])

            player.play()

            

        }

    }

Accepted Reply

Hello @dongelen,

You're on the right track here.

The log you pasted is not an actual error. That's a red-herring, which we're working on removing to reduce confusion.

I encourage you to try this again with the next seed of iOS 15; we've made a number of changes meant to enable this kind of usage.

Best regards.

Replies

Hello @dongelen,

You're on the right track here.

The log you pasted is not an actual error. That's a red-herring, which we're working on removing to reduce confusion.

I encourage you to try this again with the next seed of iOS 15; we've made a number of changes meant to enable this kind of usage.

Best regards.

Hello @dongelen,

iOS 15 beta 3 contains a lot of fixes specifically meant to enable this kind of usage of MusicKit framework. Would you mind trying this again on the latest beta build?

Thanks,

Thanks @Joekun!,

I really like the direction this api is taking! I've updated my code. And it now kind of works. I can find the album and play a song. But playing the complete album doesn't work, on iOs 15 beta 5 and tvOS.


    func searchLuwten () {

        struct MyAlbums : Codable {

            let results : Result

        }

        

        struct Result : Codable {

            let libraryAlbums : Albums

            enum CodingKeys: String, CodingKey {

                case libraryAlbums = "library-albums"

            }

        }

        struct Albums : Codable {

            let href : String

            let data : [Album]

        }

        

        Task.detached {

            let term = "LUWTEN"

            var components = URLComponents()

            components.scheme = "https"

            components.host   = "api.music.apple.com"

            components.path   = "/v1/me/library/search"

            components.queryItems =  [

                URLQueryItem (name: "term", value: term),

                URLQueryItem (name: "types", value: "library-albums")

            ]

            

            guard let url = components.url else {

                return

            }

            



            let dataRequest = MusicDataRequest(urlRequest: URLRequest(url: url))

            let dataResponse = try await dataRequest.response()

            

            let decoder = JSONDecoder()

            let albumResponse = try decoder.decode (MyAlbums.self, from: dataResponse.data)



            let player = ApplicationMusicPlayer.shared

            let album = albumResponse.results.libraryAlbums.data[0]

            let detailedAlbum = try await album.with([.artists, .tracks])

            

            

                        


            

            player.queue = [detailedAlbum.tracks![0]] // Playing one or more tracks works, but adding the complete album does not work

//            player.queue = [detailedAlbum] // This doesn't work, 
// Error is MPMusicPlayerControllerErrorDomain Code=6

            try? await player.play()

            

        }

Hello @dongelen,

Thank you very much about this additional feedback.

We can reproduce this new issue when trying to play an entire album, and we're tracking it internally.

We'll investigate this issue, and try to address it.

Thanks again.

Best regards,

  • I'm facing the same issue. From what I've noticed, the MusicItemID of a library song is different from an album song, and the player cannot play it. The same goes in the case of a library album.

    If I get the id of the library song and send another request to -

    https://api.music.apple.com/v1/me/library/songs/{id}/catalog

    And then set it to the queue; it works fine. Hoping for a fix soon!

  • Hello @snuff4,

    Thanks for the additional feedback. Could you send us a new ticket on Feedback Assistant about this issue trying to play library songs?

    Thanks,

Add a Comment

Hello @dongelen,

We have included a fix for the issue when trying to play an entire album in iOS 15.4 Beta 1.

I hope this helps.

Best regards,