在我的应用程序中,我使用The Amazing Audio Engine库播放支持音轨时录制视频。
在支持音轨的末尾,我停止录制视频。
除了在支持轨道结束之前有时调用captureOutput
方法,在它的中间。
当它追加时,我的应用程序在captureOutput
的调用之后传递给我的后备跟踪播放器的完成块,并且在我的代码中调用了captureMovieFileOutput.stopRecording()
NOWHERE。
以下是支持轨道的完成块:
audioFilePlayer.completionBlock = {
self.view.userInteractionEnabled = false
captureMovieFileOutput.stopRecording()
audioRecorder.finishRecording()
appDelegate.audioController.removeChannels(appDelegate.audioController.channels())
appDelegate.audioController.removeInputReceiver(audioRecorder)
self._activityIndicator.hidden = false
self._cancelButton.hidden = true
self._captureSession.removeOutput(captureMovieFileOutput)
self._progressView.hidden = true
self._readyGoLabel.hidden = true
self._recordAnimationView.hidden = true
self._recordAnimationView.stopAnimation()
self._restartButton.hidden = true
}
这是captureOutput
函数:
func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!) {
if !self.view.userInteractionEnabled {
if let audioRecordOutputURL = self._audioRecordOutputURL {
if let videoRecordOutputURL = self._videoRecordOutputURL {
let audioAsset = AVURLAsset(URL: audioRecordOutputURL, options: [AVURLAssetPreferPreciseDurationAndTimingKey: true])
let mutableComposition = AVMutableComposition()
let videoAsset = AVURLAsset(URL: videoRecordOutputURL, options: [AVURLAssetPreferPreciseDurationAndTimingKey: true])
self._readyGoLabel.hidden = false
for anyObject in videoAsset.tracksWithMediaType(AVMediaTypeVideo) {
if let track = anyObject as? AVAssetTrack {
var error: NSError?
let mutableCompositionTrack: AVMutableCompositionTrack
if track.mediaType == AVMediaTypeVideo {
mutableCompositionTrack = mutableComposition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: Int32(kCMPersistentTrackID_Invalid))
mutableCompositionTrack.insertTimeRange(CMTimeRange(start: kCMTimeZero, duration: track.timeRange.duration), ofTrack: track, atTime: kCMTimeZero, error: &error)
mutableCompositionTrack.preferredTransform = track.preferredTransform
}
if let error = error {
ErrorManager.defaultManager().showFatalError(title: "Error: AVFoundation", message: error.localizedFailureReason)
}
} else {
preconditionFailure("Fatal error: unreachable code.")
}
}
if let cizooPreviewViewController = self.storyboard?.instantiateViewControllerWithIdentifier(Constants.CizooPreviewViewControllerIdentifier) as? CizooPreviewViewController {
cizooPreviewViewController._cizoo = mutableComposition
cizooPreviewViewController._voiceUrl = self._audioRecordOutputURL
cizooPreviewViewController._recordedBackingTrack = self._backingTrack
self.presentViewController(cizooPreviewViewController, animated: true, completion: nil)
} else {
preconditionFailure("Fatal error: unreachable code.")
}
}
}
}
}
问题追加时,在captureOutput
方法中,我的应用未通过条件if !self.view.userInteractionEnabled
,错误为零。
我已经在iPhone 4s和iPhone 5c上看到了这个问题,而且从未在iPhone 5s和6s上看到过这个问题。