Question

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:

portrait mode landscape mode

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!

Was it helpful?

Solution

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!

OTHER TIPS

I faced a similar problem but with images. what i figured out is, you must allow rotation, that you have obviously did already.
And implement something like this:

 -(NSUInteger)supportedInterfaceOrientations{

//   if ([AppDelegate appDelegate].shoedAllowPortrait == YES) {
     // return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
   return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationLandscapeLeft;

 //  }else{
  // return UIInterfaceOrientationMaskPortrait;
 //  }
  // return UIInterfaceOrientationMaskLandscape;
 }
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
  return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate{
 return YES;
 }

 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:       (NSTimeInterval)duration {

 [self.view setNeedsDisplay];

  }

The reason is, u need to refresh your view, or the moviePlayer view, every time the device rotates. Even tray adding "viewDidRoatate" and refresh there too, is this doesn't work.

Hope this helps, Cheers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top