【发布时间】:2020-11-22 02:45:46
【问题描述】:
我创建了 MPNowPlayingInfoCenter 并将当前曲目时间和总曲目时间传递给它。 但是这样的问题就出现了。如果我在 MPNowPlayingInfoCenter 中暂停曲目,稍等片刻,然后按播放,我会看到当前时间已更改,尽管由于曲目没有播放,它应该保持在原处。如何解决这个问题?
...
func setupNotificationView(...) {
nowPlayingInfo = [String : Any]()
...
nowPlayingInfo?[MPMediaItemPropertyPlaybackDuration] = track.duration
nowPlayingInfo?[MPNowPlayingInfoPropertyElapsedPlaybackTime] = player.currentTime().seconds
nowPlayingInfo?[MPNowPlayingInfoPropertyPlaybackRate] = player.rate
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
}
...
func setupMediaPlayerNotificationView() {
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.playCommand.addTarget { [unowned self] event in
if self.player.rate == 0.0 {
self.player.play()
return .success
}
return .commandFailed
}
commandCenter.pauseCommand.addTarget { [unowned self] event in
if self.player.rate == 1.0 {
self.player.pause()
return .success
}
return .commandFailed
}
...
}
【问题讨论】:
标签: ios swift avplayer mpnowplayinginfocenter