我目前正在使用AVAssetWriter来捕获我的视频和数据。完成后,我播放我的AVPlayerItem。问题是在第一次初始播放之后,一旦调用了DidItemFinishPlaying通知,我会尝试将其重新开始。当我这样做时,avlayer消失,而不是显示处于暂停状态的海报帧。我尝试的另一件事是当我即将开始重播视频时正在做SeektoTime但是我可以在我的相机开始播放视频之前看到我的相机大约1-2秒的实时预览。这是我的代码。
let outputFileURL = NSURL(fileURLWithPath: self.outputVidFilePath)
appDel.currCamData = NSFileManager.defaultManager().contentsAtPath(outputFileURL.path!)
appDel.currCamDataType = "Video"
appDel.currCamDataURL = outputFileURL
self.vidPlayer.replaceCurrentItemWithPlayerItem(AVPlayerItem(URL: outputFileURL))
self.avLayer.hidden = false
self.playerTimer = NSTimer.scheduledTimerWithTimeInterval(0.25, target: self, selector: #selector(CameraViewController.checkPlayerStatus), userInfo: nil, repeats: true)
func checkPlayerStatus()
{
if playerTimer == nil
{
return
}
if vidPlayer.status == AVPlayerStatus.ReadyToPlay
{
if vidPlayer.currentItem != nil
{
let currentPlayItem = vidPlayer.currentItem!
if currentPlayItem.status == AVPlayerItemStatus.ReadyToPlay
{
playerTimer!.invalidate()
playerTimer = nil
if (!playerNotificationStarted) {
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(CameraViewController.itemDidFinishPlaying(_:)), name: AVPlayerItemDidPlayToEndTimeNotification, object: nil)
playerNotificationStarted = true
vidPlayer.play()
isVideoPlaying = true
}
}
}
}
}
func itemDidFinishPlaying(notification :NSNotification)
{
self.vidPlayer.seekToTime(kCMTimeZero)
self.playButton.hidden = false
self.isVideoPlaying = false
}