MPMoviePlayerController - play fullscreen - ios

Starting with this code:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieLink];
The next thing I need to do is set the player's frame and add its view as a subview. But I want it to go immediately to fullscreen, and I want it to be on top of everything else. What is the best way to do that?
If I do something like this:
[self.view addSubview:player.view];
The player does a weird resizing thing, then jumps to fullscreen. I know this is the last step:
[player setFullscreen:YES animated:NO];
But where can I add the player's view so that I don't see any weird clipping or resizing? Do I use [UIScreen mainScreen] somehow? Or access the main window of the app?

Related

How to add Video file and TextView in one UIVIEWCONTROLLER?

I want to add Video file in my iPad application.
I have use MPMoviePlayerController for this it work fine.
but i have one problem this controller is covering hole WINDOW of iPad.
I want my UIViewController should contain one textView, Navigation Bar, one Running Video file,
and four UIButton. Have can i achive this?
You can done this by add that MPMoviePlayer as subView of your view, means addSubview on your view with fix frame.
like this,
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // myView is your parent view which hold your player
[myView addSubview: player.view];
[player play];
For more references check this.

Add MPMoviePlayerController's view to a UIView

I want to add MPMoviePlayerController to a UIView.
first, I put a view in xib file, named youTubeView. youtubePlayer is the MPMoviePlayerController.
[youtubePlayer.view setFrame:youTubeView.frame];
[youTubeView addSubview:youtubePlayer.view];
[youtubePlayer play];
I want the view of youtubePlayer overlay on youTubeView. but the view of youtubePlayer goes wide, it just overlay a part of youTubeView. why ?
Try this
[youtubePlayer.view setFrame:youTubeView.bounds];
[youTubeView addSubview:youtubePlayer.view];
[youtubePlayer play];
Just assign the scaling mode for the movie like this youtubePlayer.scalingMode = MPMovieScalingModeFill;
This will solve your problem.
Happy Coding:)

Adding views to MPMoviePlayerController view after touching fullscreen button in control style MPMovieControlStyleEmbedded

I have an iPad app that has a movie preview view in the top half of the screen and thumbnails in the bottom half of the screen. When the user taps a thumbnail that movie starts playing in the movie preview view using a MPMoviePlayerViewController with control style MPMovieControlStyleEmbedded. The embedded style has the built in functionality of allowing the user to tap a fullscreen button to show the movie in fullscreen.
All of the above functionality works great but I want to always show a watermark over movies in the preview and fullscreen views. The watermark shows correctly in the preview view when I add a label to vcMoviePlayer.view but I cannot get that label to show over the movie in fullscreen mode after the fullscreen button has been pressed. I'm adding the label to vcMoviePlayer.view (making sure to bring the label to the front) when the movie player sends the MPMoviePlayerDidEnterFullscreenNotification but it still does not appear. Has anyone else seen this behavior? Does anyone know how to get a view to appear over a movie playing in fullscreen after the fullscreen button has been tapped? I've burned a lot of time trying to figure this out and any help is very very appreciated. Thanks!
I use this code and works on iOS 5 and iOS 6
UIWindow *window = [[UIApplication sharedApplication].windows objectAtIndex:0];
UIView * videoView = [[window subviews] lastObject];
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,0.0f,100.0f,100.0f)];
[videoView addSubview:customView];
On iOS 5 you have to remove the customView on MPMoviePlayerWillExitFullscreenNotification
When in fullscreen mode, MPMoviePlayerController does not use the supplied superview anymore but directly displays itself on the current (key) window.
For finding something you can put your view/s on once the player is in fullscreen mode, do as follows:
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if (!window)
{
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}
Now you can put your custom views on top of that window and it will be visible while MPMoviePlayerController is being in fullscreen mode.
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,
0.0f,
100.0f,
100.0f)];
[window addSubview:customView];
For finding the right moment to add/remove your custom views, register the following notifications and do it within the registered handlers:
MPMoviePlayerDidEnterFullscreenNotification and MPMoviePlayerWillExitFullscreenNotification

iPad presentModalViewController appears in wrong position

First of, I get the feeling apple really doesnt like us optimizing apps for landscape view.
After struggling with my app for 2 days I finally convince it to always and only show in Landscape mode. I even convinced the UIViewController that I present with presentModalViewController to appear in landscape as well. So far so good...
The position of the UIViewController that I present with UIModalPresentationFormSheet is all the way to the bottom right (with the ipad in Landscape positition). I cannot get it to move to the center like it should. Does anyone have any ideas why and or how this works and how I can make it apear in the right position?
EDIT: Added code, this code is called from a UIViewController when a button is pushed.
- (void) buttonPushed
{
pickerViewController = [[UIViewController alloc] init];
[pickerViewController.view setBackgroundColor:[UIColor whiteColor]];
_pickerCustomers = [[UIPickerView alloc] initWithFrame:CGRectMake(22,20,380,216)];
_pickerCustomers.delegate = self;
_pickerCustomers.dataSource = self;
[_pickerCustomers setShowsSelectionIndicator:YES];
[pickerViewController.view addSubview:_pickerCustomers];
_btnPickerDone = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[_btnPickerDone setFrame: CGRectMake(300,250,98,45)];
[_btnPickerDone setTitle:#"Select" forState:UIControlStateNormal];
[pickerViewController.view addSubview:_btnPickerDone];
pickerViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:pickerViewController animated:YES];
}
Have you tried playing with the little "autoposition springs" on the layout IB? Probably you have it attached to the bottom and right, simply remove those attachments.
Here's a link for you: http://disanji.net/iOS_Doc/#documentation/DeveloperTools/Conceptual/IB_UserGuide/Layout/Layout.html
Can also be done in code if you like.

How do I make a MPMovieController fullscreen view on top of a UIPopoverController?

I have successfully put a MPMoviePlayerController in a UIPopoverController by doing:
NSString *filenameString = [NSString stringWithString:[[helpVideosArray objectAtIndex:tagNumber] objectForKey:VIDEO_FILE_NAME]];
HelpVideoPopover *helpVideoPopover = [[HelpVideoPopover alloc] initWithVideoFilename:filenameString PreviewFrameView:self];
currentPopover = [[[[UIPopoverController alloc] initWithContentViewController:helpVideoPopover] retain] autorelease];
[currentPopover setPopoverContentSize:CGSizeMake(320, 240)];
[currentPopover presentPopoverFromRect:((UIButton*)sender).frame inView:previewView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
currentPopover.passthroughViews = [NSArray arrayWithObject:((HelpVideoPopover*)[currentPopover contentViewController]).movieController.view];
The problem is that when the user wants to view the video fullscreen(and I allow that) that the popover view is on top of the fullscreen video. So my question is that is there another I'm supposed to be doing this. Or maybe when I display the popover I just use a blank one and overlay a movie player on top of it from the parent view controller? I would really like to keep the movie player logic inside the popover view controller though.
Without knowing the details of your application i would imagine you could do this in several ways.
You could either open the video in a fullscreen modal view - This would cover the popover.
If you're displaying the fullscreen video in the detail-view behind the popover, then you could do something as simple as just hiding the popover once the fullscreen video has been shown.

Resources