views:

210

answers:

3

I'm trying to run a QT Movie located in my application bundle. Can't get it to work. Can someone advise?

thanks.

paul

-(IBAction)runInternalMovie:(id)sender

[


NSString *internalPath;
NSURL *internalURL;
QTMovie *internalMovie;



internalPath = [[NSBundle mainBundle] pathForResource: @"bundledMovie" 
ofType: @"mp4"];
internalURL = [NSURL fileURLWithPath: internalPath];
internalMovie = [[QTMovie alloc] initWithURL: internalURL byReference: YES];

}
+1  A: 

I always use the initWithFile: method of QTMovie:

NSError* error = nil;
NSString* moviePath = [NSBundle pathForResource:@"bundledMovie" ofType:@"mp4" inDirectory:[[NSBundle mainBundle] bundlePath]];
QTMovie* movie = [QTMovie movieWithFile:moviePath error:&error];
if(movie != nil)
{
    [movieView setMovie:movie]; 
}
else 
{
    NSLog(@"Error loading movie: %@", [error localizedDescription]);
}

Update:

If you want to use NSURL, use the following:

NSError* error = nil;
QTMovie* movie = [QTMovie movieWithURL:[[NSBundle mainBundle] URLForResource:@"bundledMovie" withExtension:@"mp4"] error:&error];
if(movie != nil)
{
    [movieView setMovie:movie]; 
}
else 
{
    NSLog(@"Error loading movie: %@", [error localizedDescription]);
}
weichsel
+2  A: 

For one thing, there is no initWithURL:byReference: method. There are many ways to create a QTMovie object, none of which have a byReference: parameter and all of which (except for +movie) take an error: output parameter.

Once you're loading the movie, you need to hand it to a QTMovieView for it to display. The easiest way to create such a view is in IB, by dragging it from the Library panel (QuickTime Kit section) to a window in one of your xibs.

Then, either have an outlet in your controller to the movie view and send the movie view a setMovie: message after creating the movie, or bind the movie view's “Movie” property to a property of your controller.

Peter Hosey
A: 

Thanks for the help everyone.

Paul.

Paul