我正在使用AVCaptureMovieFileOutput记录视频,我想添加一个UIProgressView来表示在视频停止录制之前还有多少时间。
我设定最大持续时间为15秒:
CMTime maxDuration = CMTimeMakeWithSeconds(15, 50);
[[self movieFileOutput] setMaxRecordedDuration:maxDuration];我似乎找不到AVCaptureMovieFileOutput是否有一个回调时,视频录制或录制开始。我的问题是,我怎样才能得到关于录音进展的最新信息?或者,如果这不是一个可用的东西,我如何知道什么时候开始录制,以启动一个计时器?
发布于 2014-10-23 02:51:23
下面是我如何添加一个UIProgressView
recording是AVCaptureFileOutput的一个属性,由AVCaptureMovieFileOutput扩展。
我有一个类型为movieFileOutput的变量AVCaptureMovieFileOutput,用于将数据捕获到QuickTime电影中。
@property (nonatomic) AVCaptureMovieFileOutput *movieFileOutput;我在记录属性中添加了一个观察者,以检测记录中的更改。
[self addObserver:self
forKeyPath:@"movieFileOutput.recording"
options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
context:RecordingContext];然后在回调方法中:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;我创建了一个while循环,以便在后台执行,然后确保向主线程上的视图发送更新,如下所示:
dispatch_async([self sessionQueue], ^{ // Background task started
// While the movie is recording, update the progress bar
while ([[self movieFileOutput] isRecording]) {
double duration = CMTimeGetSeconds([[self movieFileOutput] recordedDuration]);
double time = CMTimeGetSeconds([[self movieFileOutput] maxRecordedDuration]);
CGFloat progress = (CGFloat) (duration / time);
dispatch_async(dispatch_get_main_queue(), ^{ // Here I dispatch to main queue and update the progress view.
[self.progressView setProgress:progress animated:YES];
});
}
});https://stackoverflow.com/questions/26501299
复制相似问题