beginGeneratingPlaybackNotifications 似乎没有在我的应用程序中被调用。我可以获取 storeIds 并且正在播放音乐(我可以向前和向后跳过),但似乎从未调用过通知。有什么建议或有什么我想念的吗?
let player = MPMusicPlayerController.applicationQueuePlayer
// Trying all of these
player.beginGeneratingPlaybackNotifications()
MPMusicPlayerController.systemMusicPlayer.beginGeneratingPlaybackNotifications()
MPMusicPlayerController.applicationMusicPlayer.beginGeneratingPlaybackNotifications()
MPMusicPlayerController.applicationQueuePlayer.beginGeneratingPlaybackNotifications()
NotificationCenter.default.addObserver(self,
selector: #selector(refreshView),
name: .MPMusicPlayerControllerPlaybackStateDidChange,
object: self)
NotificationCenter.default.addObserver(self,
selector: #selector(refreshView),
name: .MPMusicPlayerControllerNowPlayingItemDidChange,
object: self)
let queue = MPMusicPlayerStoreQueueDescriptor(storeIDs: storeIds)
player.setQueue(with: queue)
player.play()
// Never called
@objc func refreshView(){
let nowPlaying = player.nowPlayingItem