ios - 录制的视频有时显示,有时不显示
<p><p>我有一个 ViewController ,用于记录用户的(正面)视频。使用如下代码:</p>
<pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ;
NSString *outputPath = [ initWithFormat:@"%@", ];
if ([ isDeletableFileAtPath:outputPath])
[ removeItemAtPath:outputPath error:NULL];
NSURL *outputURL = [ initFileURLWithPath:outputPath];
;
self.outputURL = outputURL;
</code></pre>
<p>其中 <code>movieFileOutput</code> 是 <code>AVCaptureMovieFileOutput</code> 对象。我可以向您展示相机配置/设置代码(这不是图像选择器 Controller 或任何 Apple UI;它会在用户与完全不同的屏幕交互时在后台拍摄用户),但总的来说,我知道它可以工作。 </p>
<p>然后,调用 <code>;</code> 并将用户导航到一个新屏幕,在该屏幕上播放刚刚发生的录制。我将 <code>outputURL</code> 对象传递给这个 <strong>newly initialized</strong>ViewController ,VC 使用以下代码播放它:</p>
<pre><code>self.player = [ initWithContentURL:self.outputURL];
self.player.view.frame = CGRectMake(0, 0, self.view.frame.size.width, 320);
self.player.movieSourceType = MPMovieSourceTypeFile;
[ addObserver:self selector:@selector(moviePlaybackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player];
self.player.controlStyle = MPMovieControlStyleNone;
self.player.shouldAutoplay = YES;
;
;
];
;
</code></pre>
<p>所以,第一次,一切正常。应用程序录制视频,然后显示下一个屏幕,并显示视频。但是,如果您单击“放弃”按钮,它会一直回到应用程序的开头,并再次执行整个过程,它确实<strong>不起作用</strong>,而是播放器显示黑色屏幕。话虽如此,我打印出路径上的数据长度,它<strong>总是</strong>很大(因此该路径上存在某些东西)。</p>
<p>奇怪的是,我决定像这样打印 <strong>NSData</strong> 对象本身:</p>
<pre><code>NSLog(@"%@", );
</code></pre>
<p>确实打印了一个非常大的字符串(也许是字节?不确定)。 <strong>然而</strong>,由于某种原因,现在一切正常...当我<strong>添加此 NSLog()</strong> 时,该错误不再出现。当我删除它时,它再次发生!我已经<strong>严格</strong>对此进行了测试。</p>
<p>但是仍然有一些奇怪的时间包含这个 NSLog() 时,在播放了三遍黑屏之后。我很困惑为什么会出现这个错误,以及包含 NSLog() 究竟如何改变任何行为。</p>
<p>有什么想法吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我的猜测是你需要等待文件被保存。</p>
<p><a href="https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureFileOutput_Class/#//apple_ref/occ/instm/AVCaptureFileOutput/stopRecording" rel="noreferrer noopener nofollow"><code>AVCaptureFileOutput</code></a> 的文档说:</p>
<blockquote>
<p>When recording is stopped either by calling this method, by changing
files using <code>startRecordingToOutputFileURL:recordingDelegate:</code>, or
because of an error, <strong>the remaining data that needs to be included to
the file will be written in the background. Therefore, before using
the file, you must wait until the delegate that was specified in
<code>startRecordingToOutputFileURL:recordingDelegate:</code> is notified when all
data has been written to the file using the
<code>captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error:</code>
method.</strong></p>
</blockquote></p>
<p style="font-size: 20px;">关于ios - 录制的视频有时显示,有时不显示,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/34253004/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/34253004/
</a>
</p>
页:
[1]