I’ve tried each doable technique to subscribe and I am not getting any notifications
let musicPlayer = MPMusicPlayerController.systemMusicPlayer
let appMusicPlayer = MPMusicPlayerController.applicationMusicPlayer
let queuePlayer = MPMusicPlayerController.applicationQueuePlayer
func subscribe() {
MPMediaLibrary.requestAuthorization { _ in }
musicPlayer.beginGeneratingPlaybackNotifications()
appMusicPlayer.beginGeneratingPlaybackNotifications()
queuePlayer.beginGeneratingPlaybackNotifications()
NotificationCenter.default.addObserver(forName: .MPMusicPlayerControllerPlaybackStateDidChange, object: musicPlayer, queue: .foremost) { [weak self] notification in
debugPrint("hey")
}
NotificationCenter.default.addObserver(forName: .MPMusicPlayerControllerPlaybackStateDidChange, object: appMusicPlayer, queue: .foremost) { [weak self] notification in
debugPrint("hey")
}
NotificationCenter.default.addObserver(forName: .MPMusicPlayerControllerPlaybackStateDidChange, object: queuePlayer, queue: .foremost) { [weak self] notification in
debugPrint("hey")
}
NotificationCenter.default.addObserver(
self,
selector: #selector(playbackStateChanged(_:)),
title: .MPMusicPlayerControllerPlaybackStateDidChange,
object: musicPlayer
)
NotificationCenter.default.addObserver(
self,
selector: #selector(playbackStateChanged(_:)),
title: .MPMusicPlayerControllerPlaybackStateDidChange,
object: appMusicPlayer
)
NotificationCenter.default.addObserver(
self,
selector: #selector(playbackStateChanged(_:)),
title: .MPMusicPlayerControllerPlaybackStateDidChange,
object: queuePlayer
)
}