Dismiss lock screen player after playback is finished in iOS

I am using AVFoundation framework and more specifically

AVPlayer
along with
AVPlayerItem
to play an audio content. I am also setting
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
,
AVAudioSession.sharedInstance().setActive(true)
,
MPNowPlayingInfoCenter.default().nowPlayingInfo = // some value
and using
MPRemoteCommandCenter
commands. As usual it is showing a default player on iPhone lock screen as shown in figure.


My question is once the playback of audio is finished the default iPhone lock screen player does not goes away. I am resetting all the above info e.g

AVAudioSession.sharedInstance().setActive(false)
and
MPNowPlayingInfoCenter.default().nowPlayingInfo = nil
and
audioPlayer.replaceCurrentItem(with: nil)
etc. How can I make this lock screen player hide after the playback is finished.

Replies

Does anyone have a solution for this issue now?
Lock screen behavior is most likely handled by the MP classes, which I believe is part of the MediaPlayer framework. I recommend asking the question in that part of the forums.