0

如何查看使用以下 QTKit 代码转换电影的进度?

NSDictionary *dict = [NSDictionary 
     dictionaryWithObjectsAndKeys:
     [NSNumber numberWithBool:YES], QTMovieExport, 
     [NSNumber numberWithLong:kQTFileType3GPP], 
     QTMovieExportType, nil];

[[movieView movie] writeToFile:@"/tmp/sample.3gp" 
     withAttributes:dict];

即我想查看电影转换的进度,以便可以在进度条中显示它。

4

1 回答 1

1

取自本网站: http: //www.mactech.com/articles/mactech/Vol.21/21.08/Threads/index.html

如果影片非常大,此方法可能需要很长时间才能完成。在此期间,用户将无法对应用程序执行任何操作,只能移动窗口。不是很令人兴奋。

稍微好一点的解决方案是使用 movie:shouldContinueOperation:withPhase:atPercent:withAttributes: 委托方法。这是围绕 QuickTime 的电影进度功能的包装,将用于显示一个对话框,显示导出进度并允许用户取消操作。这里试试这个

- (BOOL)movie:(QTMovie *)movie 
      shouldContinueOperation:(NSString *)op 
      withPhase:(QTMovieOperationPhase)phase 
      atPercent:(NSNumber *)percent 
      withAttributes:(NSDictionary *)attributes
{
   OSErr err = noErr;
   NSEvent *event;
   double percentDone = [percent doubleValue] * 100.0;

   switch (phase) {
      case QTMovieOperationBeginPhase:
         // set up the progress panel
         [progressText setStringValue:op];
         [progressBar setDoubleValue:0];

         // show the progress sheet
         [NSApp beginSheet:progressPanel 
            modalForWindow:[movieView window] modalDelegate:nil 
            didEndSelector:nil contextInfo:nil];
         break;
      case QTMovieOperationUpdatePercentPhase:
         // update the percent done
         [progressBar setDoubleValue:percentDone];
         [progressBar display];
         break;
      case QTMovieOperationEndPhase:
         [NSApp endSheet:progressPanel];
         [progressPanel close];
         break;
   }

   // cancel (if requested)
   event = [progressPanel 
         nextEventMatchingMask:NSLeftMouseUpMask 
         untilDate:[NSDate distantPast] 
         inMode:NSDefaultRunLoopMode dequeue:YES];
   if (event && NSPointInRect([event locationInWindow], 
                                          [cancelButton frame])) {
      [cancelButton performClick:self];
      err = userCanceledErr;
   }

   return (err == noErr);
}

希望这可以帮助。

如果您需要任何帮助,请告诉我。如果这对 lil 有帮助,请告诉我。

PK

于 2010-10-03T04:46:04.720 回答