Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

QTMovie frameImageAtTime in NSThread Problem



I'm trying to load information from a number of video files in an NSThread, using the following code.


- (void)loadVideoInformationInBackground:(id)sender { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSManagedObject *theVideo = nil; NSURL *theFileURL = nil; NSError *theError; int counter;

// Find all of the videos that have not finished loading.
for( counter = 0; counter < [[videoController arrangedObjects] count]; counter++ )
{
theVideo = [[videoController arrangedObjects] objectAtIndex:counter];


// If this video has not been loaded, then load it.
if( theVideo && [[theVideo valueForKey:@"loaded"] boolValue] == false)
{
// Get the path of this video's file.
theFileURL = [NSURL URLWithString:[theVideo valueForKey:@"path"]];
if( theFileURL )
{
QTMovie *theMovie = [QTMovie movieWithURL:theFileURL error:&theError];


                [snip]

                if( theMovie )
                {
                    [snip]

// Duration
double durationInSeconds;
QTTime qtDuration = [[theMovie attributeForKey:QTMovieDurationAttribute] QTTimeValue];
if( QTGetTimeInterval( qtDuration, &durationInSeconds) )
{
NSNumber *duration = [[NSNumber alloc] initWithDouble:durationInSeconds];
[theVideo setValue:duration forKey:@"duration"];
[duration release];
}


// Thumbnail
QTTime middle = QTMakeTime ( qtDuration.timeValue / 2, qtDuration.timeScale );
NSImage *theThumbnail = [theMovie frameImageAtTime:middle ];
[theVideo setValue:[NSArchiver archivedDataWithRootObject:theThumbnail] forKey:@"thumbnail"];


                    [snip]
                }
            }
        }
    }


[pool release]; }

I know this code works when run from the main thread, but when it's run from a new thread, it gets stuck waiting for a semaphore at the line:
NSImage *theThumbnail = [theMovie frameImageAtTime:middle ];


Can this be called from outside the main thread? If not, is there a work around?

I've been looking through the sample code that demonstrates using multiple threads in QuickTime, and none of the examples use NSThread. Instead they use posix threads. Is this the problem with my code? Do I need to switch to posix threads?

Any assistance is appreciated.

Regards,
David



_______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-API mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-api/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.