ApplicationMusicPlayer plays only song from user defined playlists

Hello,

I'm trying out the new Apple MusicKit and I have some strange behavior. When I set de queue it is only possible to play song from user defined playlists. Is this the right behavior?

Tracks is an

var tracks: MusicItemCollection<Track>?

                        ApplicationMusicPlayer.shared.queue = ApplicationMusicPlayer.Queue(for: viewModel.tracks!, startingAt: viewModel.tracks?.first!)

                        try await ApplicationMusicPlayer.shared.play()

Hello @foxoffire33,

Thanks for your question about MusicKit.

We need more information about your use case in order to help you understand this issue.

How are you fetching this collection of tracks in the first place? It would really help us to see the the code you're using to fetch this data.

Also, can you be more specific about what you mean when you say "user defined playlists"?

Best regards,

Thanks for your response

By user defined playlists, I mean playlist created by de user. The issue if with catalog playlists When a user adds a catalog playlist, and I'm get all the songs from that playlist, I can't play them with a startingAt position

I'm new with swift that is way I wanted to know if it is my fault

Below is the code I used to fetch all songs from a playlist

    private func buildRequest(urlString: String) throws -> URLRequest {

        //setting up ure for use
        let requestUrl =  URL(string: urlString)!

        //settingup request accept only json
        var request = URLRequest(url: requestUrl)
        request.addValue("application/json", forHTTPHeaderField: "Accept")
        request.addValue("application/json", forHTTPHeaderField: "Content-Type")
        return request
    }

    func getTracks(playlistID: MusicItemID) async -> MusicItemCollection<Song>? {
        do{
            if try await self.isAuthenticated() {
                let request = try self.buildRequest(urlString: "https://api.music.apple.com/v1/me/library/playlists/" + playlistID.rawValue + "/tracks")
                let response =  try await MusicDataRequest(urlRequest: urlRequest).response()
                if response != nil {
                    let decoder = try self.decoder.decode(MusicItemCollection<Song>.self, from: response!.data)
                    return decoder
                }
            }
        } catch {
            print("Error info: \(error)")
        }
        return nil
    }
code-block

Best regards

Accepted Answer

Hello @foxoffire33,

Ok, thanks for this. As long as your library playlist only doesn't contain any music video, this way of fetching the list of tracks should work. If you did want to support playlists with songs or music videos, I would recommend you replace MusicItemCollection<Song> with MusicItemCollection<Track>.

That said, at the end of the day, I think the only way for us to help you with this question is for you to file a new ticket on Feedback Assistant including a sysdiagnose.

Also, if you wouldn't mind including a bit more of your code so we could see the way you connect up your getTracks call to your view model, that would be helpful.

Best regards,

ApplicationMusicPlayer plays only song from user defined playlists
 
 
Q