iPad video in portrait mode - ios

I have made an iPad video in portrait mode i.e. 768*1024. Now when I convert it in mp4 format the converter converts it into 1024*768 i.e landscape mode.Is there any way to show the portrait video in portrait mode or any software to convert the portrait video in mp4 portrait mode?
or I would have to make the video again in landscape mode?
I am using MPMoviePlayerController.
Thanks in advance.

MPMoviePlayerController no longer works in landscape by default so to make it work in landscape you need to apply a transform to the view.
UIView * playerView = [moviePlayerController view];
[playerView setFrame: CGRectMake(0, 0, 480, 320)];//iPhone
CGAffineTransform landscapeTransform;
landscapeTransform = CGAffineTransformMakeRotation(90*M_PI/180.0f);
landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80);
[playerView setTransform: landscapeTransform];
In addition, if you want the regular full screen controls, use the following sample.
moviePlayerController.fullscreen = TRUE;
moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;
This is for your information "playing a video with MPMoviePlayerController in Portrait WITHOUT Private API-Will get rejected by Apple".Good luck and happy coding :-)

Related

Video playback works on iPhone but not on iPad

I'm trying to get video to play on top of an OpenGL context and it works fine on an iPhoneX, but on my iPad Pro I get a black screen. Audio plays and there are no errors in the log to indicate that something might be wrong.
This is the code I have:
NSString *path = [[NSBundle mainBundle] pathForResource:title ofType:#"m4v"];
self.player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:path]];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
CGRect rect = CGRectMake(0, 0, 480, 320);
self.playerLayer.frame = rect;
[[[Director sharedDirector] openGLView].layer addSublayer:self.playerLayer];
[_player play];
I'm aware that 480x320 is very small on a 12" iPad, but the parent view has its scaleX/scaleY properties set to upsize it (again, this works fine on iPhoneX, and even for the OpenGL content on the iPad)
The code was originally using the deprecated MPMediaPlayerController, and I tried using MPMediaPlayerViewController as well, just as I've tried all of the various voodoo tricks suggested here on StackOverflow for black-screen video and the result is always the same.
Anyone with similar experience and a way to fix it?
Adding to [[Director sharedDirector] openGLView].layer.superLayer instead of [[Director sharedDirector] openGLView].layer fixed the problem.
I still don't get why this would be different between iPhone and iPad, or why it doesn't throw some kind of error on the iPad if it doesn't work. (FWIW, both works on the iPhone)

Is Apple using black magic to accomplish camera's preview orientation?

I have this AVFoundation camera app of mine. The camera preview is the result of a filter, applied by didOutputSampleBuffer method.
When I setup the camera I am following what apple did on one of their sample codes (CIFunHouse):
// setting up the camera
CGRect bounds = [self.containerOpenGL bounds];
_eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
_videoPreviewView = [[GLKView alloc] initWithFrame:bounds
context:_eaglContext];
[self.containerOpenGL addSubview:_videoPreviewView];
[self.containerOpenGL sendSubviewToBack:_videoPreviewView];
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
NSDictionary *options = #{kCIContextUseSoftwareRenderer : #(NO),
kCIContextPriorityRequestLow : #(YES),
kCIContextWorkingColorSpace : [NSNull null]};
_ciContext = [CIContext contextWithEAGLContext:_eaglContext options:options];
[_videoPreviewView bindDrawable];
_videoPreviewViewBounds = CGRectZero;
_videoPreviewViewBounds.size.width = _videoPreviewView.drawableWidth;
_videoPreviewViewBounds.size.height = _videoPreviewView.drawableHeight;
dispatch_async(dispatch_get_main_queue(), ^(void) {
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI);
_videoPreviewView.transform = transform;
_videoPreviewView.frame = bounds;
});
self.containerOpenGL is a full screen view and is constrained to the four corners of the screen. Autorotation is on.
But this is the problem...
When I setup the GLKView and self.ciContext it is created assuming the device is on a particular orientation. If the device is on a particular orientation and I run the application, the previewView will fit the entire self.containerOpenGL area but when I rotate the device the previewView will be out center.
I see that Apple code works perfectly and they don't use any constraints. They do not use any autorotation method, no didLayoutSubviews and when you rotate the device, running their code, everything rotates except the preview view. And worse than that, my previewView appears to rotate but not their's.
Is this black magic? How do I they do that?
They add their preview view to a uiwindow and that is why it does not rotate. I hope this answers the question. If not I will continue to look through their source code.
Quote from source code.
we make our video preview view a subview of the window, and send it to the back; this makes FHViewController's view (and its UI elements) on top of the video preview, and also makes video preview unaffected by device rotation
They also add this
_videoPreviewView.enableSetNeedsDisplay = NO;
This may keep it from responding as well
Edit: It appears that now the preview rotates and the UI does as well so to combat this you can add a second window and send it to the back and make the main window clear and add the previewView to the second window with a dummyViewController that tells it not to autorotate by overriding the appropriate method. This will allow the preview to not rotate but the UI to rotate.

iOS YTPlayerView force video quality

I am currently using iOS-youtube-player-helper library in our application. There is a view controller, with a YTPlayerView that has an aspect ratio of 16:9, which means it takes only a part of the screen. The video is loaded in medium and no matter how, I could not get it to play in 720P or 1080P. I am certain that these qualities are available, it's just the YTPlayerView forcing the quality based on the video player height. Because this is a library and not direct iframe embed, I cannot use "vq" parameter(specifying vq in playerVars does not seem to work), and setting the quality to be small then change it later does not work either(refer to this issue on GitHub)
Now, given the factor that I cannot make the YTPlayerView to fill up the whole screen, because of UI designing issues. So, is it possible to force the YTPlayerView to play in at least 720P? (Workarounds, changing the library code, ...)
Because this is an app that will be on App Store(and of course we don't want to have any legal disputes with google either), please don't suggest using libraries that are against the Youtube ToC such as XCDYouTubeKit
Many Thanks
I've found a workaround and this works well for me.
First of all, the problems depends by the webView size constructed inside the YTPlayerView. For example if you have a 320x200 playerView, try to forcing your video to 720hd don't work because the iFrame youtube player class re-switch to a better resolution according to your player size (in this case small quality because you have 320x200).
You can see this SO answer that explain this issue.
When you have imported the YTPlayerView class to your project you have two files: YTPlayerView.h and YTPlayerView.m
YTPlayerView.m (Update to work also on iPads)
I've change the function where the webview is initialized with a custom size (4k resolution) and to the last part I've added the possibility to scale the contents and restore the original frame, like this:
- (UIWebView *)createNewWebView {
CGRect frame = CGRectMake(0.0, 0.0, 4096.0, 2160.0); //4k resolution
UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
//UIWebView *webView = [[UIWebView alloc] initWithFrame:self.bounds];
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
webView.scrollView.scrollEnabled = NO;
webView.scrollView.bounces = NO;
if ([self.delegate respondsToSelector:#selector(playerViewPreferredWebViewBackgroundColor:)]) {
webView.backgroundColor = [self.delegate playerViewPreferredWebViewBackgroundColor:self];
if (webView.backgroundColor == [UIColor clearColor]) {
webView.opaque = NO;
}
}
webView.scalesPageToFit = YES;
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
CGSize contentSize = webView.scrollView.contentSize;
CGSize viewSize = self.bounds.size;
float scale = viewSize.width / contentSize.width;
webView.scrollView.minimumZoomScale = scale;
webView.scrollView.maximumZoomScale = scale;
webView.scrollView.zoomScale = scale;
// center webView after scaling..
[webView setFrame:CGRectMake(0.0, self.frame.origin.y/3, 4096.0, 2160.0)];
} else {
webView.frame = self.bounds;
}
[webView reload];
return webView;
}
Hope this helps who try to use the Youtube original player in his project.
P.S.: All my tries were did with a swift project and the following vars:
var playerVars:Dictionary =
["playsinline":"1",
"autoplay":"1",
"modestbranding":"1",
"rel":"0",
"controls":"0",
"fs":"0",
"origin":"https://www.example.com",
"enablejsapi":"1",
"iv_load_policy":"3",
"showinfo":"0"]
Using the functions:
self.playerView.load(withVideoId: "Rk6_hdRtJOE", playerVars: self.playerVars)
and the follow method to force the resolution:
self.playerView.loadVideo(byId: "Rk6_hdRtJOE", startSeconds: 0.0, suggestedQuality: YTPlaybackQuality.HD720)
About iPads:
As reported by Edward in comments there was a little problem on iPads, that's because these devices seems don't apply scalesPageToFit. The goal is to check if the device is an iPad, then to scale (zooming out) the scrollView to host the little view bounds.
I've tested on my iPad air and it works. Let me know.

iOS : How to Full screen video when change device orientation to Landscape in MPMoviePlayerController?

I am developing an application with MPMoviePlayerController. The application supports Portrait mode only. But I want to change the video in full Screen when I change the device orientation to landscape and back to half screen when change device orientation to Portrait.
if in Landscape and Full Screen mode and movie finishes then also go to half screen mode.
I have tried different codes and options but could not succeed. please help.
My Source code
#property (nonatomic,strong) MPMoviePlayerController* moviePlayer;
-(void)PlayVideoContent
{
CGFloat x = 0;
CGFloat y = 70;
CGRect mpFrame = CGRectMake(x, y, SCREEN_WIDTH, 200);
NSString * introVideoFileName = #"video_5.mp4";
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:introVideoFileName ofType:#""]];
MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
controller.scalingMode = MPMovieScalingModeAspectFill;
self.moviePlayer = controller; //Super important
// controller.view.frame = self.view.bounds; //Set the size
controller.view.frame = mpFrame; //Set the size
// [self.moviePlayer setFullscreen:YES animated:YES];
[self.view addSubview:self.moviePlayer.view]; //Show the view
[self.moviePlayer play]; //Start playing
}
U must give the UIViewController(s) of your application to decide whether it's in landscape or portrait.
After that, set all the rest to portrait except the one u want in landscape (the MPMoviePlayerController)
In your project settings (App Target > General > Deployment Info > Device Orientation), select Portrait, Landscape Left and Landscape Right.
In your root view controller, add:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
If everything gets loaded into this view controller, that should be all you have to do. If you find that some views are rotating when they shouldn't, add this same code to their view controllers.
The controller for the fullscreen video will use the supported orientations specified in the target settings, and so will allow rotation to landscape. When you close the video, the view will rotate back to portrait.

My app does not support Portrait mode but at times it turning into portrait mode

My app does not support Portrait mode but at times it turning into portrait mode. I am using Xcode 5.02 & I am running my app on iOS7. I unchecked the portrait mode in the settings so that it does not support portrait, but at a point of time it is turning into portrait, I dont have any clue, any one to help me out, my app is master-detail base. This below code snippet in app delegate & dashboardNavController is UINavigationController
self.window.rootViewController = self.dashboardNavController;
[self.window makeKeyAndVisible];
if needed I am glad to provide more informations, Thanks in advance
Try this in ViewDidLoad
CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI/2);
self.view.transform = transform;
// Repositions and resizes the view.
// If you need NavigationBar on top then set height appropriately
CGRect contentRect = CGRectMake(0, 0, self.view.size.height, self.view.size.width);
self.view.bounds = contentRect;

Resources