2011-12-29 3 views
2

から他のメソッドを呼び出す方法.mp4.caf.movに結合するのに次のコードを使用しています。 (注:私はそのためのコードを与えるいけない動画を再生する方法を知っている)ビデオを再生するためのでiPhone:[_assetExport exportAsynchronouslyWithCompletionHandler:^(void){}

AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition 
                     presetName:AVAssetExportPresetPassthrough]; //AVAssetExportPresetPassthrough 

NSString* videoName = @"export.mov"; 

NSString *exportPath = [document stringByAppendingPathComponent:videoName]; 
NSURL *exportUrl = [NSURL fileURLWithPath:exportPath]; 
NSLog(@"Export : %@",exportUrl); 

if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) 
{ 
    [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil]; 
} 

_assetExport.outputFileType = AVFileTypeQuickTimeMovie;//@"com.apple.quicktime-movie"; 
NSLog(@"file type %@",_assetExport.outputFileType); 
_assetExport.outputURL = exportUrl; 
_assetExport.shouldOptimizeForNetworkUse = YES; 

[_assetExport exportAsynchronouslyWithCompletionHandler: 
^(void) { 
    switch (_assetExport.status) 
    { 
     case AVAssetExportSessionStatusCompleted: 
      // export complete 

      NSLog(@"Export Complete"); 
     ------>>> // From Here I want play movie using MPMoviePlayerController.<<<--------- 


      break; 
     case AVAssetExportSessionStatusFailed: 
      NSLog(@"Export Failed"); 
      NSLog(@"ExportSessionError: %@", [_assetExport.error localizedDescription]); 

      //    export error (see exportSession.error) 
      break; 
     case AVAssetExportSessionStatusCancelled: 
      NSLog(@"Export Failed"); 
      NSLog(@"ExportSessionError: %@", [_assetExport.error localizedDescription]); 

      //    export cancelled 
      break; 

    } 


}  

]; 

を私は他の方法[self playVideo]と呼ばれるが、そのは再生できません。

私はこのアプローチを使用しようとしています。b'coz [_assetExport exportAsynchronouslyWithCompletionHandler: ^(void) { }は、ビデオを書き出すために他のスレッドを使用します。

私は[self playVideo]に上記のコードの後に​​電話しようとするとします。上記の方法ではまだビデオが作成されているので、ビデオは取得できません。

私もAVAssetExportSessionStatusCompletedから通知しようとしましたが、再生していないビデオです。

私の質問はどのように私はその方法からビデオを再生できますか?または、私はビデオを正常に再生できるようにメインスレッドに制御を切り替える方法は?このような

+0

は、私はビデオの品質を求めていないですAVAssetExportPresetMediumQuality – Splendid

+0

にAVAssetExportPresetPassthrough変更を試してみてください。 – Devang

+0

エクスポートした後でビデオを取得していますか?あなたのNSDocumentdirectorを保存してください。 – Splendid

答えて

6

[self performSelectorOnMainThread:@selector(playVideo) withObject:nil waitUntilDone:NO]; 
+0

あなたはちょうど私に挫折の時間を節約しました、ありがとう! – kevlar

関連する問題