Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate a video 90º in MPMovieplayercontroller

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 enter image description here

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

like image 441
thavasidurai Avatar asked Sep 10 '13 08:09

thavasidurai


3 Answers

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 :)

like image 157
Camo Avatar answered Oct 27 '22 01:10

Camo


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];
like image 42
Mystery Avatar answered Oct 27 '22 01:10

Mystery


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.

like image 38
Ravi_Parmar Avatar answered Oct 27 '22 02:10

Ravi_Parmar