I am trying to play video inside a UIView
, so my first step was to add a class for that view and start playing a movie in it using this code:
- (IBAction)movie:(id)sender{ NSBundle *bundle = [NSBundle mainBundle]; NSString *moviePath = [bundle pathForResource:@"Movie" ofType:@"m4v"]; NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain]; MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; theMovie.scalingMode = MPMovieScalingModeAspectFill; [theMovie play]; }
But this just crashes the app when using this method inside it's own class, but is fine elsewhere. Does anyone know how to play video inside a view? and avoid it being full screen?
As of the 3.2 SDK you can access the view property of MPMoviePlayerController
, modify its frame and add it to your view hierarchy.
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; player.view.frame = CGRectMake(184, 200, 400, 300); [self.view addSubview:player.view]; [player play];
There's an example here: http://www.devx.com/wireless/Article/44642/1954
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With