How i play video in swift Using AVPlayerViewController

56 views Asked by At

Am using PHPicker to get videos in my photos library Photos. Getting Video from PHPicker

func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
    self.dismiss(animated: true)
    results.forEach { result in
        if result.itemProvider.hasItemConformingToTypeIdentifier(UTType.movie.identifier) {
            result.itemProvider.loadItem(forTypeIdentifier: UTType.movie.identifier, options: [:]) { videoUrl, phpError in
                if let url = videoUrl as? URL {
                    // Here is Video URL
                }
            }
        }
    }
}

And here is my video player code

func playVideo(url: URL) {
    let player = AVPlayer(url: url)
    playerVC = AVPlayerViewController()
    playerVC.player = player
    playerVC.allowsPictureInPicturePlayback = true
    playerVC.player?.play()
    self.present(playerVC, animated: true)
}

when i select and play a video am getting this

VIdeo player image

0

There are 0 answers