Trust me, all the videos on you tube will work for earlier versions of iOS, but

I needed it to work for me in iOS 4.2, and after a lot of mix and match of code, found the following to

work well.  Here is the code in the ViewController implementation :

-(IBAction)playMovie {

//Get the Movie

NSBundle *bundle = [NSBundle mainBundle];

NSString *moviePath = [bundle pathForResource:@"sample_iPod" ofType:@"m4v"];

NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];

theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

//Place it in subview, else it won’t work

theMovie.view.frame = CGRectMake(0, 0, 480, 320);

[self.view addSubview:theMovie.view];

//Resize window – a bit more practical

UIWindow *moviePlayerWindow = nil;

moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];

[moviePlayerWindow setTransform:CGAffineTransformMakeScale(0.9, 0.9)];

// Play the movie.

[theMovie play];

}
I have this setting for LandScape on a iPhone 4.

About these ads