1

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

    ]

}
Iam Wayne
  • 561
  • 6
  • 26
  • As mentioned in error message your `self. AudioPlayer.currentItem` is nil. So you cant do that. You should probably check why `currentItem` is nil. – adev Aug 06 '17 at 05:35

0 Answers0