2012-11-08 78 views
1

我使用AVAssetWriter編碼從圖像組視頻第一棄用:finishWriting被棄用:在IOS 6.0

[assetWriter finishWriting]; 

,並且此方法在IOS產生一個警告信息6.

[assetWriter finishWritingWithCompletionHandler:<#^(void)handler#>]; 

這是怎樣的方式我應該在iOS 6中應用它。任何人都可以幫助我應用它

回答

9

你不需要檢查它是否完成。完成處理程序是一個塊。寫作完成後系統會調用它。嘗試一下。

[assetWriter finishWritingWithCompletionHandler:^(){ 
    NSLog (@"finished writing"); 
}]; 
+0

可以ü請與示例代碼解釋更 – mychar

+0

[assetWriter finishWritingWithCompletionHandler:^(){ } completionHandler:^(BOOL完成){如果(完成)NSLog(@「完成的寫作」);} } ];你可以這樣解釋,這段代碼有錯誤 – mychar

+0

[assetWriter finishWritingWithCompletionHandler:^(){ NSLog(@「finished writing」); }];這一個dosen't工作,我嘗試it.It崩潰的應用程序,請幫助我 – mychar

1

這是作家開始代碼

NSURL *movieURL = [NSURL fileURLWithPath:myPathDocs1]; 
    NSError *movieError = nil; 
    [assetWriter release]; 
    assetWriter = [[AVAssetWriter alloc] initWithURL:movieURL 
              fileType: AVFileTypeQuickTimeMovie 
               error: &movieError]; 
    NSDictionary *assetWriterInputSettings = [NSDictionary dictionaryWithObjectsAndKeys: 
               AVVideoCodecH264, AVVideoCodecKey, 
               [NSNumber numberWithInt:FRAME_WIDTH], AVVideoWidthKey, 
               [NSNumber numberWithInt:FRAME_HEIGHT], AVVideoHeightKey, 
               nil]; 
    assetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType: AVMediaTypeVideo 
                  outputSettings:assetWriterInputSettings]; 
    assetWriterInput.expectsMediaDataInRealTime = YES; 
    [assetWriter addInput:assetWriterInput]; 

    [assetWriterPixelBufferAdaptor release]; 
    assetWriterPixelBufferAdaptor = [[AVAssetWriterInputPixelBufferAdaptor alloc] 
            initWithAssetWriterInput:assetWriterInput 
            sourcePixelBufferAttributes:nil]; 
    [assetWriter startWriting]; 

    firstFrameWallClockTime = CFAbsoluteTimeGetCurrent(); 
    [assetWriter startSessionAtSourceTime: CMTimeMake(0, TIME_SCALE)]; 

    // start writing samples to it 
    [assetWriterTimer release]; 
    assetWriterTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f/60.0f 
                 target:self 
                 selector:@selector (writeSample:) 
                 userInfo:nil 
                 repeats:YES] ; 

這是作家停止代碼

if (isRecording) { 
     isRecording = NO; 
     [_session stopRunning]; 
     [assetWriterTimer invalidate]; 
     assetWriterTimer = nil; 


     [assetWriter finishWritingWithCompletionHandler:^(){ 
      NSLog (@"finished writing"); 
     }]; 


     [self loadOvelay]; 

    } 
相關問題