Search code examples
objective-cqtkit

How do I view the progress for converting a Movie with QTKit?


How do I view the progress for converting a Movie with the following QTKit code?

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

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

i.e. I want to view the progress of the movie conversion such that I can display it in a progress bar.


Solution

  • Taken from this site: http://www.mactech.com/articles/mactech/Vol.21/21.08/Threads/index.html

    If the movie is very large, this method could take quite a while to complete. During that time, the user would be unable to do anything with the application except move windows around. Not very exciting.

    A slightly better solution involves using the movie:shouldContinueOperation:withPhase:atPercent:withAttributes: delegate method. This is a wrapper around QuickTime's movie progress function, which will be used to display a dialog box showing the progress of the export and to allow the user to cancel the operation. Here try this

    - (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);
    }
    

    Hope this helps.

    If you need any help do let me know. let me know if this helped a lil.

    PK