I am using AVPlayer to stream audio files from url, that work fine. The issue is the palyback duration (MPMediaItemPropertyPlaybackDuration) is not showing in the control center. The title and artwork is showing, but not duration slider. Getting error: unexpectedly found nil while unwrapping an Optional value This is what I've tried so far, any help would be appreciated. Thanks
My code:
func setLockInfo() {
let art = MPMediaItemArtwork(image: UIImage(named:holdImage)!)
MPNowPlayingInfoCenter.default().nowPlayingInfo = [
MPMediaItemPropertyTitle :titlename,
MPMediaItemPropertyArtwork : art,
MPNowPlayingInfoPropertyPlaybackRate: 1,
**// This giving the error**
MPMediaItemPropertyPlaybackDuration: NSNumber(value : CMTimeGetSeconds(audioPlayer.currentItem!.asset.duration)),
**//This way didnt work**
// MPMediaItemPropertyPlaybackDuration: CMTimeGetSeconds ((self. AudioPlayer. currentItem?. asset. duration)!),
MPNowPlayingInfoPropertyElapsedPlaybackTime: 0
]
}