I'm using AVKit to show videos to a user.
When the user selects a video it is presented using the standard player from AVKit. This makes it fullscreen.
If the user elects to make it 'Picture in Picture' the user is able to continue using the rest of the application.
This means the user is able to choose another video to play, which indeed does play (in fullscreen) at the same time as the previous video which is still visible in picture in picture.
I'd like to close the first (PiP) video when the second video is selected, however, before launching the 2nd video I try to 'dismiss' the previous, but it doesn't work.
I think it's because it's being shown as a PiP so the AVPlayerViewController doesn't represent it anymore...
Is there a way to do this simply?
Playing a video with the (not working) attempt to kill the first video if the second is trying to be played:
func play(FileName filename: String, FileType type: String)
{
if self.isVideoPlaying == YES
{
self.playerController!.dismiss(animated: YES, completion: { self.isVideoPlaying = NO ; self.play(FileName: filename, FileType: type) })
return
}
self.isVideoPlaying = YES
let path = Bundle.main.path(forResource: filename, ofType: type)
let url = NSURL(fileURLWithPath: path!)
let player = AVPlayer(url: url as URL)
...