ios 16 - Previous screen is skipped while closing the video fullscreen mode and ondisappear is calling while enter into fullscreen mode

Viewed 16

struct ...: View {

var body: some View {
    VStack {
        if let player = self.player {
            AVPlayerControllerRepresented(player: player)
        }
    }.onAppear {
       
    }.onDisappear() {
       
    }
}

}

struct AVPlayerControllerRepresented : UIViewControllerRepresentable { var player : AVPlayer var showControls: Bool = true var videoGravity: AVLayerVideoGravity = .resizeAspect

func makeUIViewController(context: Context) -> AVPlayerViewController {
    let controller = AVPlayerViewController()
    controller.player = player
    controller.showsPlaybackControls = showControls
    controller.videoGravity = videoGravity
    controller.delegate = context.coordinator
    controller.modalPresentationStyle = .overFullScreen
    player.allowsExternalPlayback = true
    player.usesExternalPlaybackWhileExternalScreenIsActive = true
    return controller
}

func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) {
    
}

func makeCoordinator() -> AVPlayerPresetationDelegate {
    return AVPlayerPresetationDelegate(self)
}

class AVPlayerPresetationDelegate: NSObject, AVPlayerViewControllerDelegate {
   
    var parent: AVPlayerControllerRepresented
        
           init(_ parent: AVPlayerControllerRepresented) {
               self.parent = parent
           }
    func playerViewController(_ playerViewController: AVPlayerViewController, willBeginFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    }
    
    func playerViewController(_ playerViewController: AVPlayerViewController, willEndFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) {
      
    }
    
}

}

0 Answers
Related