I'm having trouble setting the currentTime and songLength of the MPNowPlayingInfoCenter. Here's my code:
func updateNowPlayingCenter (title: String, artist: String, albumArt: AnyObject, currentTime: NSNumber, songLength: NSNumber, PlaybackRate: Double){
var songInfo: Dictionary <NSObject, AnyObject> = [
MPMediaItemPropertyTitle as NSObject: title as AnyObject,
MPMediaItemPropertyArtist as NSObject: artist as AnyObject,
MPMediaItemPropertyArtwork as NSObject: ???,
MPNowPlayingInfoPropertyElapsedPlaybackTime as NSObject: currentTime,
MPMediaItemPropertyPlaybackDuration as NSObject: songLength,
MPNowPlayingInfoPropertyPlaybackRate as NSObject: PlaybackRate as AnyObject
]
MPNowPlayingInfoCenter.default().nowPlayingInfo = songInfo as [NSObject : AnyObject] as! [String : Any]
}
And here's where I set the properties in the viewWillAppear:
updateNowPlayingCenter(title: titleText[thisSong], artist: authorText[thisSong], albumArt: ??? as AnyObject, currentTime: ???, songLength: ???, PlaybackRate: 1.0)
I tried to use audioPlayer.currentTime and audioPlayer.duration, but it didn't work. How do I do this? Also, I can't figure out how to set the image of the MPMediaItemPropertyArtwork. I have the files in my assests and the image name equals the titleText[thisSong]. If you could also help me with that, that would be awesome! Thanks!