0

In my application, I am trying to play a video in both landscape and portrait mode using MPMoviePlayerController. I have written a piece of code for playing video & handling its rotation. My present code is working completely fine in ios 7 but in ios 8 the issue is that on changing the rotation of ipad to landscape, the video still runs in portrait mode in respect to that position. Can anyone suggest me a way so that I can get out of this issue.

My present code is:

NSURL *videoURL = [NSURL fileURLWithPath:urlFromPrevious];

moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
moviePlayerController.scalingMode = MPMovieScalingModeAspectFit;
moviePlayerController.fullscreen=YES;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:moviePlayerController];

[[moviePlayerController view] setFrame:CGRectMake(x_axe_forImage, y_axe_forImage, width_forImage, height_forImage+44)];

[[self view] addSubview:[moviePlayerController view]];

[moviePlayerController play];
valbu17
  • 4,034
  • 3
  • 30
  • 41
iYoung
  • 3,596
  • 3
  • 32
  • 59
  • Maybe you might wanna try using `UIWindowDidBecomeVisibleNotification` or `UIWindowDidBecomeHiddenNotification` for your notifications.. – valbu17 Oct 28 '14 at 16:03
  • I've copy pasted this code into a new project, it works fine in the iOS8 simulator suggesting that your problem lies elsewhere. Perhaps you've implemented a rotation callback method in the ViewController that the video is embedded in and that is screwing with your video. Keep in mind that in iOS8 Apple completely deprecated all the rotation callbacks and introduced -willTransitionToTraitCollection:withTransitionCoordinator: and -viewWillTransitionToSize:withTransitionCoordinator:, make sure you hanle those. – Zoltán Matók Oct 28 '14 at 17:12
  • @ZoltánMatók: Thanks for investing your time for my issue. I have found hwere my problem was occuring & now I had solved it. – iYoung Oct 29 '14 at 06:59
  • @RajatDeepSingh No problem. May I ask what the issue was at the end? – Zoltán Matók Oct 30 '14 at 10:37
  • @RajatDeepSingh So what was it? – Zoltán Matók Oct 30 '14 at 12:12

1 Answers1

0

Take a look at How to use MPMoviePlayerController. You have to present that view controller with the proper UIViewController selector: 'presentMoviePlayerViewControllerAnimated'

Community
  • 1
  • 1
nstefan
  • 187
  • 2
  • 8
  • I am working with MPMoviePlayerController not MPMoviePlayerViewController so, I can't use presentMoviePlayerViewControllerAnimated – iYoung Oct 28 '14 at 14:25
  • Well with this approach, since MPMoviePlayerController is not a UIViewController subclass, I'd suggest you to set it's view autoresizingMask to UIViewAutoresizingFlexibleWidth and UIViewAutoresizingFlexibleHeight. – nstefan Oct 28 '14 at 14:35