Reputation: 702
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.
I'm using MPMusicPlayerController.systemMusicPlayer
to access information about the currently playing music item on the Music.app.
On iOS devices, nowPlayingItem
correctly returns the metadata of the currently playing music item.
However, when running the same code on MacCatalyst, nowPlayingItem
consistently returns nil
, even though playbackState
indicates 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.
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!
Upvotes: 1
Views: 97