I'm encountering an issue with MPMusicPlayerController.systemMusicPlayer.nowPlayingItem on MacCatalyst, where it returns nil even though playbackState reports .playing.
This behavior differs from iOS, where the expected music item is returned.
Here's a summary of the problem:
I'm using
MPMusicPlayerController.systemMusicPlayerto access information about the currently playing music item on the Music.app.On iOS devices,
nowPlayingItemcorrectly returns the metadata of the currently playing music item.However, when running the same code on MacCatalyst,
nowPlayingItemconsistently returnsnil, even thoughplaybackStateindicates that music is playing (playbackState == .playing).I've verified that my app has the necessary authorization to access the user's media library, and there are no errors reported during authorization.
This issue occurs consistently across different MacCatalyst environments and OS versions.
Here's the relevant code snippet:
import MediaPlayer
MPMediaLibrary.requestAuthorization { status in
if status == .authorized {
if let nowPlayingItem = MPMusicPlayerController.systemMusicPlayer.nowPlayingItem {
// This block is never executed on MacCatalyst
let title = nowPlayingItem.title ?? "Unknown Title"
let artist = nowPlayingItem.artist ?? "Unknown Artist"
print("Currently Playing: \(title) by \(artist)")
} else {
// This block is always executed on MacCatalyst
print("No music is currently playing.")
}
} else {
print("Authorization denied.")
}
}
I've searched through Apple's documentation and developer forums, but I haven't found any specific information about this issue or any known workarounds.
Any insights or suggestions on why nowPlayingItem returns nil on MacCatalyst while the playback state is .playing, and how to resolve or work around this issue, would be greatly appreciated. Thank you!
systemMusicPlayer _establishConnectionIfNeeded failed [application failed to launch]. I think that means the XPC connection has failed in macCatalyst.