I am creating an iOS iPad application that, among other things, utilizes the MPMoviePlayerController
on one of the screens, underneath another view, named "CommandMessageView." Here are the relevant parts of my .h file:
@interface MovieViewController : UIViewController
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
@property (strong, nonatomic) IBOutlet UIView *MovieView;
@property (strong, nonatomic) IBOutlet UIView *CommandMessageView;
And then the relevant parts of the .m file:
@implementation MovieViewController
@synthesize MovieView;
@synthesize moviePlayer;
@synthesize CommandMessageView;
- (void)viewDidLoad {
[super viewDidLoad];
// Video Setup
NSURL *currentVideoURL = [NSURL URLWithString:
self.currentVideo];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:currentVideoURL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[moviePlayer.view setFrame: MovieView.bounds];
moviePlayer.shouldAutoplay = NO;
[MovieView addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
}
The video plays fine, except for if the view is rotated to portrait, in which the video is placed about mid-screen and only the first 2/3 (horizontally) is visible. If it helps, screenshots can be seen here:
What I was hoping for is that the UIView MovieView, which is set up for autolayout (almost full-screen) would define the boundary of where the video could fit inside, as well as the correct layer (commandMessageView appears on top of it). Obviously, something is off, but after tweaking numerous options, haven't made any leeway. Is there something obvious I am missing here/doing wrong, or something to fix in interface builder that you can think of? Thanks for help in advance!
Not sure exactly how this works, but adding the line:
[moviePlayer.view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
right after
[moviePlayer.view setFrame: MovieView.bounds];
Got me the desired behavior.
Happy coding, everyone!