0

我在我的应用程序中录制视频时遇到问题。记录 54 秒后,应用程序退出活动状态。有没有办法在视频录制停止之前阻止它?这是我用来录制视频的代码:

  captureSession = <initialized capture session> //using the back camera and the mic
  movieFileOutput = [[AVCaptureMovieFileOutput alloc]init];
  if( ![captureSession canAddOutput:movieFileOutput])
  {
      NSLog(@"Can't add movie file output!");
      return;
  }

[self.captureSession beginConfiguration];
[captureSession addOutput:movieFileOutput];
[self.captureSession commitConfiguration];

NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];

NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];

NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:now];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:now];
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;

NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:now] autorelease];
NSString *caldate = [destinationDate description];
NSString *recorderFilePath = [[NSString stringWithFormat:@"%@/%@.mov", DOCUMENTS_FOLDER, caldate] retain];
NSURL *url = [NSURL fileURLWithPath:recorderFilePath];
[recorderFilePath release];



[captureSession startRunning];
for ( AVCaptureConnection *connection in [movieFileOutput connections] ) 
{
    for ( AVCaptureInputPort *port in [connection inputPorts] ) 
    {
        if ([[port mediaType] isEqual:AVMediaTypeVideo] ) 
        {
            if([connection isVideoOrientationSupported]) 
            {
                [connection setVideoOrientation: [[UIDevice currentDevice] orientation]];
            }

        }
    }
}
[movieFileOutput startRecordingToOutputFileURL:url recordingDelegate:self];
isRecording = YES;
NSLog(@"Started video recording.");
4

0 回答 0