Saturday, 24 November 2018

Video not being correctly displayed on preview controller

I currently have 2 VC one for handles the video taking and the other for the preview of the video on another VC. So when I start holding a button on the screen its supposed to start recording, yet instead It does nothing for a couple seconds and then just segues to a blank view controller which was supposed to have contain the captured video. I should note that this code is a friends whole project I tried to add to a blank Xcode, so I would think its an integration problem. So the question is what is going wrong? Why does this happen and how can I fix? Suggestions of more info to provide are welcome

A link to the full project is here.

Bellow can be found the VideoPlayback VC:

class VideoPlayback: UIViewController {

//receives url video value from VideoViewController
var videoURL: URL!

//place where video gets displayed
@IBOutlet weak var videoView: UIView!

let avPlayer = AVPlayer()

private var playerQueue: AVQueuePlayer!
private var playerItem1: AVPlayerItem!
private var playerLooper: AVPlayerLooper!
private var playerLayer: AVPlayerLayer!

override func viewDidLoad() {
    super.viewDidLoad()

    print(avPlayer, "avPlayer")
    print("videoURL", videoURL)

    playerItem1 = AVPlayerItem(url: videoURL as URL)
    print(playerItem1, "player item 1")

    playerQueue = AVQueuePlayer(playerItem: playerItem1)
    print(playerQueue, "player queue")

    playerLayer = AVPlayerLayer(player: playerQueue)
    print(playerLayer, "playerLayer")

    playerLooper = AVPlayerLooper(player: playerQueue, templateItem: playerItem1)
    print(playerLooper, "player looper")

    playerLayer.frame = view.bounds
    playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
    videoView.layer.insertSublayer(playerLayer, at: 0)

    view.layoutIfNeeded()
    self.playerQueue?.play()
}

}

Bellow can be found the method wich I think has somthing to do with the issue:

    func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
    print("START Finish")


    if (error != nil) {
        print("Error recording movie: \(error!.localizedDescription)")
    } else {

        print("START else Finish")

        let videoRecorded = outputURL! as URL

        performSegue(withIdentifier: "showVideo", sender: videoRecorded)
        print("START else Finish")

    }
}



from Video not being correctly displayed on preview controller

No comments:

Post a Comment