Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Force full screen video

I'm using a MPMoviePlayerViewController. When the video loads and starts playing it doesn't fill up the whole screen. I have to press the full screen button at the top right to make that happen. If I use MPMoviePlayerController I can't get it to fill the screen at all.

Any way via code that I can get my video full screen using the MPMoviePlayerViewController without having to press the fullscreen button?

I know i'm using a private API here, but thats ok, it is for a demo.

Code:

- (void)viewDidLoad
{
[super viewDidLoad];


[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"phatpad" ofType:@"mov"];

if (moviePath)
{
    NSURL *url = [NSURL fileURLWithPath:moviePath];
    player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
}

player.view.frame = self.view.frame;

[self.view addSubview: player.view];

}

Here is a screen. The first is without pressing the full screen button, the second is after pressing it. enter image description here

like image 376
spentak Avatar asked Aug 24 '11 17:08

spentak


1 Answers

You have to set the fullscreen attribute to true and the scallingMode to the aspect fill like this:

if (moviePath)
{
    NSURL *url = [NSURL fileURLWithPath:moviePath];
    player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
    player.moviePlayer.fullscreen = YES;
    player.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
}

I have tested at home and it works, so I hope to you too.

like image 135
Yannick Loriot Avatar answered Oct 04 '22 14:10

Yannick Loriot