Swift 控制中心';的进度视图不会暂停
我已经为我的Swift 控制中心';的进度视图不会暂停,swift,progress-bar,mpmediaitem,mpnowplayinginfocenter,Swift,Progress Bar,Mpmediaitem,Mpnowplayinginfocenter,我已经为我的AVAudioPlayer设置了控制中心。除了control center中的进度条外,一切都很正常,只要暂停AVAudioPlayer,进度条就会继续计数。我怎样才能解决这个问题?以下是我目前掌握的情况: func updateNowPlayingCenter (title: String, artist: String, currentTime: AnyObject, songLength: AnyObject, PlaybackRate: Double){
AVAudioPlayer
设置了控制中心。除了control center中的进度条外,一切都很正常,只要暂停AVAudioPlayer
,进度条就会继续计数。我怎样才能解决这个问题?以下是我目前掌握的情况:
func updateNowPlayingCenter (title: String, artist: String, currentTime: AnyObject, songLength: AnyObject, PlaybackRate: Double){
let image:UIImage = UIImage(named: title)!
let artwork = MPMediaItemArtwork.init(boundsSize: image.size, requestHandler: { (size) -> UIImage in
return image
})
var songInfo: Dictionary <NSObject, AnyObject> = [
MPMediaItemPropertyTitle as NSObject: title as AnyObject,
MPMediaItemPropertyArtist as NSObject: artist as AnyObject,
MPMediaItemPropertyArtwork as NSObject: artwork,
MPNowPlayingInfoPropertyElapsedPlaybackTime as NSObject: currentTime,
MPMediaItemPropertyPlaybackDuration as NSObject: songLength,
MPNowPlayingInfoPropertyPlaybackRate as NSObject: PlaybackRate as AnyObject
]
MPNowPlayingInfoCenter.default().nowPlayingInfo = songInfo as [NSObject : AnyObject] as! [String : Any]
}
override func remoteControlReceived(with event: UIEvent?) {
if event?.type == UIEventType.remoteControl {
if event?.subtype == UIEventSubtype.remoteControlPlay {
audioPlayer.play()
} else if event?.subtype == UIEventSubtype.remoteControlPause {
audioPlayer.pause
} else if event?.subtype == UIEventSubtype.remoteControlNextTrack {
nextButtonTapped()
} else if event?.subtype == UIEventSubtype.remoteControlPreviousTrack {
previousButtonTapped()
}
}
}
我使用的是Swift 3和Xcode 8
updateNowPlayingCenter(title: titleText[thisSong], artist: authorText[thisSong], currentTime: audioPlayer.currentTime as AnyObject, songLength: audioPlayer.duration as AnyObject, PlaybackRate: 1.0)