AVPlayerLayer is nil



我正在拍摄视频,拍摄完成后,我将尝试在AVPlayerLayer上预览拍摄的视频。

拍摄视频后,我会将url保存到DocumentsDirectory。此url也保存在AVCaptureFileOutputRecordingDelegate的">didFinishRecordingTo">函数为";outputFileURL";。

我为didFinishRecordingTo函数编写了下面的代码。

创建了具有相对url的AVplayer,创建了AVPlayerLayer作为"em";previewLayer"与相应的AVPlayer。但我仍然在打印下面的一行,上面写着";预览层nil"我也试过打印(previewLayer(,但它说它是零。

为什么会发生这种情况?

感谢

private var previewLayer : AVPlayerLayer?
let player = AVPlayer(url: outputFileURL)

previewLayer? = AVPlayerLayer(player: player)
previewLayer?.videoGravity = .resizeAspectFill
previewLayer?.frame = cameraView.bounds
print(previewLayer)
guard let previewLayer = previewLayer else {
print("preview Layer nil")
return
}

cameraView.layer.addSublayer(previewLayer)
previewLayer.player?.play()
recordButton.isHidden = true

previewLayer?中删除?(仅在下面的行中(,因为这将使默认为的行变得无用

previewLayer? = AVPlayerLayer(player: player)
nil = AVPlayerLayer(player: player)

这使得previewLayer为零,所以让它成为

previewLayer = AVPlayerLayer(player: player)

相关内容

  • 没有找到相关文章

最新更新