简体   繁体   中英

Black screen using AVPlayer (both in simulator and in device)

Using this code in an @IBAction of a button the video player opens up but it only shows a black screen. I can't figure out why. Thanks

if let path = Bundle.main.path(forResource: "Timelapse Stabilizzata", ofType: "mov") {
        let video = AVPlayer(url: URL(fileURLWithPath: path))
        let videoPlayer = AVPlayerViewController()


        videoPlayer.player = video

        present(videoPlayer, animated: true, completion: {
            video.play()
        })

Try to change UIwindowLevel , maybe there is a view appears above the player level

         if let path = Bundle.main.path(forResource: "Timelapse Stabilizzata", ofType: "mov") {
                let video = AVPlayer(url: URL(fileURLWithPath: path))
                let videoPlayer = AVPlayerViewController()

                videoPlayer.view.window?.windowLevel = 0
                videoPlayer.player = video
                present(videoPlayer, animated: true, completion: {
                    video.play()
                })
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM