Queue cleared.
Apple Music player reset successfully.
Queued track: Uncle Salty with PlayParameters present.
Play Parameters: PlayParameters(id: 1660109276, kind: "song", isLibrary: nil, catalogID: nil, libraryID: nil, deviceLocalID: nil, rawValues: [:])
Queue contains 1 entries.
prepareToPlay failed [no target descriptor]
Error during playback for Uncle Salty: The operation couldn’t be completed. (MPMusicPlayerControllerErrorDomain error 1.)
Notification BASS DSD NSConcreteNotification 0x600003cd70e0 {name = kUpdateSongInfo; object = {
AlbumTitle = "Toys In the Attic";
ArtistName = Aerosmith;
SongArtwork = "<NSImage 0x60000873dd60 Size={300, 300} RepProvider=<NSImageArrayRepProvider: 0x6000034711c0, reps:(\n "NSBitmapImageRep 0x600001eace00 Size={300, 300} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=300x300 Alpha=NO Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x600003cb0040"\n)>>";
SongLength = "249.754";
SongTitle = "Uncle Salty";
Source = AppleMusic;
}}
Changes to the code: private let player = ApplicationMusicPlayer.shared
// MARK: - Play Single Track
public func playTrack(_ track: Track) async {
guard let playParameters = track.playParameters else {
print("Error: Track \(track.title) is missing PlayParameters. Cannot play.")
return
}
let status = await MusicAuthorization.request()
if status != .authorized {
print("Music authorization not granted.")
}
do {
// Insert the track into the queue
try await player.queue.insert(track, position: .afterCurrentEntry)
print("Queued track: \(track.title) with PlayParameters present.")
print("Play Parameters:", track.playParameters ?? "None")
// Log the queue state
if player.queue.entries.isEmpty {
print("Queue is still empty after inserting track \(track.title).")
return
}
print("Queue contains \(player.queue.entries.count) entries.")
self.notifyAppleMusicTrackInfo(track)
// Prepare and play
try await player.prepareToPlay()
try await player.play()
print("Playback started for track: \(track.title)")
} catch {
print("Error during playback for \(track.title): \(error.localizedDescription)")
}
}