How to rotate a video 90º in MPMovieplayercontroller - iphone

I am using MPMovieplayercontroller to play video it plays the video which comes from web services. Source video file was taken in potrait mode but it has been rotated 90º in anti-clockwise direction. So when i am playing it in MPMovieplayercontroller it is playing like following format attached is the sample image
Is there any way to rotate the video file which comes from web service?
I have tried to apply transform for MPMovieplayercontroller.view but movie player controls also rotating. my requirement is i would need to rotate the video part only. Is there any way to achieve this. Please help me out to fix this it would be great help.
Thanks in advance

try with this: (I have made a subclass for MPMoviePlayerViewController)
- (void)configureSubViews
{
if (self.moviePlayer.view.subviews.count > 0)
{
UIView *view = self.moviePlayer.view.subviews[0];
if (view.subviews.count > 0)
{
UIView *sView = view.subviews[0];
self.viewPlayerVideoContent = [sView viewWithTag:1002];
self.viewPlayerControls = [sView viewWithTag:1003];
}
}
}
I don't really like to work in that way with the subViews, but it works.. (at least for iOS5 and iOS6)
then, you could try to rotate the viewPlayersVideoContent :)

You need to rotate MPMoviePlayer view as per the following code.
This will work best. I have tested it.
NSURL *fileUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Video" ofType:#"mp4"]];
MPMoviePlayerViewController *moviePlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:fileUrl];
[moviePlayerController.moviePlayer prepareToPlay];
[moviePlayerController.moviePlayer setRepeatMode:MPMovieRepeatModeOne];
[moviePlayerController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
moviePlayerController.view.transform = CGAffineTransformMakeRotation(M_PI/2);
[self.view addSubview:moviePlayerController.view];

You may achieve this by following code,
yourMoviePlayerController.view.transform = CGAffineTransformMakeRotation(M_PI/2);
and if you want to keep you controls at some place fixed, by default its not possible. So you need to hide the default controls by following code,
yourMoviePlayerController.controlStyle = MPMovieControlModeHidden;
and then add a subView for the controls programatically.

Related

How can i add a video as a HUD element in iphone sdk

I want to add a video that shows up when i call it but not a typical (stretch-to-bounds) view
similar to the ProgressHud view that loads in the middle and darkens the background. how can I load a video say from LBYoutubeController or natively?
Thanks!
edit: ideally the video box will take up 60-70 % of the screen but again will be centered and overshadowing the background
You need to use a MPMoviePlayerController. You can set the controlStyle to MPMovieControlStyleEmbedded and this will give you a player with no controls. Set the scalingMode to MPMovieScalingModeFill to make the video conform to the frame you set for it regardless of the video's natural layout. Just add the movie player's view to your view hierarchy and you're good to go.
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] init];
moviePlayer.scalingMode = MPMovieScalingModeFill;
moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
[myView addSubview:moviePlayer.view];
To add a dimming view behind this:
UIView *back = [[UIView alloc]initWithFrame:myView.bounds];
back.backgroundColor = UIColor.blackColor;
back.alpha = 0.7;
[myView insertSubview:back belowSubview:myView];

iOS - entire View shifts up after rotation

Doing a very simple iPad app that plays a video in fullscreen. I want the video perfectly centered, but on initial load it's a bit too far down. When I rotate it, the view resets itself properly to be perfectly centered. Obviously I'd love to have it look this way from the start.
Here's my code in viewDidLoad:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"movie" ofType:#"m4v"]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer prepareToPlay];
CGRect screenBounds = [UIScreen mainScreen].bounds;
[moviePlayer.view setFrame:CGRectMake(0, 0, screenBounds.size.height, screenBounds.size.width)];
[self.view addSubview:moviePlayer.view];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[moviePlayer play];
[super viewDidLoad];
The app is set to only show in landscape mode, so the rotation takes effect every 180 degrees (instead of 90). BTW the moviePlayer var is set in the .h file like so:
#property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
Then it's synthesized in my ViewController:
#synthesize moviePlayer;
So does anyone have any ideas? I tried changing "setFrame" to start at 0,-20 instead of 0,0 but that messed things up on the later rotations. If there's a way to ignore the dumb status bar on initial load, I'd love to know it. Thanks.
Try setting the frame in -viewDidLayoutSubviews. Layout should be handled there, not in the setup methods.
Try calling
[self setWantsFullScreenLayout:YES];
in the viewcontroller implementation. This should force it to "ignore the dumb status bar on initial load".

How to include a video in my apps intro?

I am creating an iphone app using cocos2d and I was wondering if it would be possible to play a video as an intro of the scene and if its possible how would I do that and what video format should I use?
Just additional info on what I mean
I am looking to include a small animation like Cut the rope has, a small animation before a scene is loaded.
Add MediaPlayer framework to your project.
Add this header file
#import <MediaPlayer/MediaPlayer.h>
NSURL *urlString = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"SAP_Business_Analytics_new_audio_low" ofType:#"mov"]];
player = [[MPMoviePlayerController alloc] initWithContentURL:urlString];
[[player view] setFrame: [self.view frame]]; // frame must match parent view
[self.view addSubview: [player view]];
[player play];

mpmovieplayercontroller issue

one small issue in my movieplayer..![movieplayer shows like this]
1: http://i.stack.imgur.com/WujxB.png but i want to show as below screenshot
mycode:
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
moviePlayerController.view.frame = CGRectMake(0,0,320,460);
moviePlayerController.fullscreen = YES;
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];
Those are the default controls for fullscreen playback, since you set moviePlayerController.fullscreen = YES.
The controls you want are for embedded playback, not fullscreen.
What you want is moviePlayerController.controlStyle = MPMovieControlStyleEmbedded; but you can only use it if your movie is embbeded in one of your views. Then you would have the controls that you want, including a toggle between fullscreen and embedded.
You have to use MPMoviePlayerViewController instead of using MPMoviePlayerController.

MPMoviePlayerController visible while loading stream

Any one know how to keep the MPMoviePlayerController visible while the movie is loading.
Or before the movie is ready to play?
For some reason it only shows up when the Movie is ready to play.
Heres what I have.
mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:[mp view]];
mp.view.frame = mediaPlayerContainer.frame;
[mediaPlayerContainer removeFromSuperview];
mp.useApplicationAudioSession = YES;
mp.shouldAutoplay = YES;
mp.controlStyle = MPMovieControlStyleFullscreen;
My mediaPlayerContainer is just a dummy container so I can visually build a frame for my mp view.
The only other thing I can think of doing is using a "screenshot" of a player as a place holder. And removing it if the player is in "play" mode.
That seems janky though.
Thnks.
MPMoviePlayerController has a backgroundView property...
You can add an UIImageView to it and it should be displayed while it is loading the video.