Why does the MPMoviePlayerController call MPMoviePlayerPlaybackDidFinishNotification, when enter in fullsceen mode - ios6

I want to display a MPMoviePlayerViewController in full screen mode, but when the fullscreen button of the movieplayercontroller view is beeing pressed, first the MPMoviePlayerWillEnterFullscreenNotification gets called, as expacted, but than the MPMoviePlayerPlaybackDidFinishNotification is also beeing sent. As a reason it says MPMovieFinishReasonPlaybackEnded and i don't know, what i'm doing wrong. (In addition, i use iOS 6.0 and XCode 4.5.1)
My expactations are, that only the MPMoviePlayerWillEnterFullscreenNotification is beeing called.
Short explanation to the code below:
The MovieplayerViewController's view is beeing displayed in a tiny subview in my content view. When tapping the fullscreen-button, it first gets displayed as fullscreen but than also calls the exit button and stops playing (no crashes, nothing else).
MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[playerViewController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
[playerViewController.moviePlayer setScalingMode:MPMovieScalingModeFill];
CGRect rect = videoView.frame;
rect.origin = CGPointZero;
[playerViewController.view setFrame:rect];
[playerViewController.moviePlayer prepareToPlay];
//movie this is my contents subview, where i add the viewcontroller's view as a subbview
[self.videoView addSubview:playerViewController.view];
[self.videoView setHidden:NO];
playerViewController.moviePlayer.useApplicationAudioSession = NO;
[playerViewController.moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidFinishNotification:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerWillEnterFullscreenNotification:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerWillExitFullscreenNotification:)
name:MPMoviePlayerWillExitFullscreenNotification
object:playerViewController.moviePlayer];
//i store the movieplayer in a property, so i can use it for further operations
self.myPlayer = playerViewController;
[playerViewController release];
And thats it!
When the resize (or fullscreen) button is being pressed, the moviePlayerDidFinishNotification: method also is being called
- (void)moviePlayerDidFinishNotification:(NSNotification*) aNotification {
int reason = [[[aNotification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (reason == MPMovieFinishReasonPlaybackEnded) {
//movie finished playin
//in debug mode, it stops right at the NSLog
NSLog(#"");
}
else if (reason == MPMovieFinishReasonUserExited) {
//user hit the done button
}
else if (reason == MPMovieFinishReasonPlaybackError) {
//error
}
.. }
Is there something i do wrong or is there probably a change since iOS 6.0?

Ok, seems to be that there are some problems in the MPMoviePlayerViewController. What helped is to simply us the MPMoviePlayerController only.

For future reference the reason that your player showed in a small window was because you were setting:
[playerViewController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
[playerViewController.moviePlayer setScalingMode:MPMovieScalingModeFill];
CGRect rect = videoView.frame;
rect.origin = CGPointZero;
[playerViewController.view setFrame:rect];
[playerViewController.moviePlayer prepareToPlay];
//movie this is my contents subview, where i add the viewcontroller's view as a subbview
[self.videoView addSubview:playerViewController.view];
[self.videoView setHidden:NO];
When you use an MPMoviePlayerViewController it creates it's own view controller. These calls are not necessary and will only create bizarre behavior. That's why the MPMoviePlayerController worked properly because it's designed to work inside another view controller.

Related

I have searched but could not find the one unique and proper method

I have a registration form in which i have used around 7 textfields. But when i starts to enter the values in that the keyboard hides the lower 3 fields.I want to move up my view but not by using scroll view.Please tell me any solution for that.
Thanks.
Register for Keyboard Show and Hide Notification.
- (void)registerForKeyboardNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
--
Now in the - (void)keyboardWasShown:(NSNotification*)iNotification method, get the Keyboard Size using
NSDictionary *anUserInfo = [iNotification userInfo];
CGSize aKeyboardSize = [[anUserInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
Based on the device being iPhone 5 or iPhone 4, get the size of screen too.
Now you will be in a position to figure out the hidden fields and distance the view has to slide up to make the hidden fields visible.
Use - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField delegate of the TextField. Everytime, a hidden textfield is about to be edited, calculate the distance it should move up to be visible.
Once you get the distance, animate the view to move up.
How to move up:
CGFloat aDistanceToMakeFieldVisible = 50.0; //you have to calculate this
[UIView animateWithDuration:0.5 animations:^{
CGRect aFrame = self.view.frame;
aFrame.origin.y -= aDistanceToMakeFieldVisible;
self.view.frame = aFrame;
} completion:^(BOOL finished) {
}];
Dont forget to Animate Down too...

Programmatically show and hide the popover (MasterViewController) in UISplitViewController (Master-Detail Template)

I want to add a button that show/hides the popover, similarly to the one of the DropBox app.
(In both landscape & portrait)
I have tried many solutions, but at this stage I don't even want to muddy the water with my attempts. If you've done this, or know how to do this, please send me in the right direction!
Thanks!
it appears it's quite simple.
Set some object to be delegate of splitViewController. In my case (I create all viewcontrollers programatically) that was appdelegate.
UISplitViewController* splitViewController = [[UISplitViewController alloc] init];
[splitViewController setViewControllers:#[navigationViewController1, navigationViewController2]];
splitViewController.delegate = self;
Implement delegate method to hide master in portrait orientation:
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation {
return UIInterfaceOrientationIsPortrait(orientation);
}
Actually add barButtonItem:
-(void)splitViewController:(UISplitViewController *)svc
willHideViewController:(UIViewController *)aViewController
withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)pc {
UINavigationController* slaveNavigationViewController = svc.viewControllers[1];
UIViewController* slaveViewController = slaveNavigationViewController.viewControllers[0];
[barButtonItem setTitle:#"Your master title"];
slaveViewController.navigationItem.leftBarButtonItem = barButtonItem;
}
In this method, you get barButtonItem which you customize and add to slaveViewController.
And last one, remove the button in landscape orientation:
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
UINavigationController* slaveNavigationViewController = svc.viewControllers[1];
UIViewController* slaveViewController = slaveNavigationViewController.viewControllers[0];
[barButtonItem setTitle:#"Drops"];
slaveViewController.navigationItem.leftBarButtonItem = nil;
}
That's it.
There's a simpler, undocumented way to do it. For an existing UIButton:
[button addTarget: theSplitViewController action: #selector(toggleMasterVisible:) forControlEvents:UIControlEventTouchUpInside];
This target/action are the same as for the barButtonItem sent in the willHideViewController function.

scroll top and bottom with page control

Using scrollview with page control for displaying different pages. want to scroll up and down on each page. How can i do that.
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width * 3, self.view.frame.size.height)];
[scrollView setDelegate:self];
[scrollView setPagingEnabled:YES];
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
// Add our views to the scroll view
[scrollView addSubview:pageOne.view];
[scrollView addSubview:pageTwo.view];
[scrollView addSubview:pageThree.view];
[self.view addSubview:self.scrollView];
_pageControl = [[UIPageControl alloc] init];
[_pageControl setCurrentPage:0];
[_pageControl setNumberOfPages:3];
[_pageControl sizeToFit];
[_pageControl setFrame:CGRectMake((scrollView.frame.size.width / 2) - (_pageControl.frame.size.width / 2), scrollView.frame.size.height - _pageControl.frame.size.height, _pageControl.frame.size.width, _pageControl.frame.size.height)];
[self.view addSubview:self.pageControl];
How can i enable scrolling up and down on each page.
Thanks for help.
You need to monitor the UIControlEventValueChanged event to determine when the page control has changed pages. You can do this programmatically view the addTarget method.
[_pageControl addTarget:self action:#selector(positionChanged)
forControlEvents:UIControlEventValueChanged];
This tells the page control to call the positionChanged method in the current object, whenever the page is changed. The positionChanged method can then look at the currentPage of the page control to determine where to move to.
So the positionChanged method might look something like this:
- (void)positionChanged {
NSUInteger page = [_pageControl currentPage];
CGFloat yoffset = self.view.frame.size.height * page;
[scrollView setContentOffset:CGPointMake(0,y)];
}
Don't forget that you'll need to call removeTarget sometime before your object is destroyed, possibly in your dealloc method.
[_pageControl removeTarget:self action:#selector(positionChanged)
forControlEvents:UIControlEventValueChanged];
Code hasn't been tested, but hopefully that's enough to get you started.
If you don't want to do this programmatically, you can also connect your page control to the positionChanged method using the Xcode Interface Builder. The details are explained in the Xcode User Guide.

Rotation Not working in iOS-6.0 and above versions

I have prepared one view controller file named "CncWindowController" and In XIB file, i take window object (instead of UIView) and connected it to view outlet. So when I access its view, i get window object.
I'm accessing like it in AppDelegate.m file :
self.windowController = [[CncWindowController alloc] initWithNibName:#"CncWindowController" bundle:nil];
self.window = (UIWindow*) self.windowController.view;
Here, view is actually referring to window. But Rotation is not working in iOS6.0 and shouldAutorotate method is also not called.
If i will use window object like below then it works fine :
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
What is wrong with my approach ? Any help of ideas how i should work autorotation in iOS-6 too using above approach ?
Thanks!

Custom segue with left to right animation going diagonal instead

I'm building an app where the first view has a menu panel, and I want this panel to stick around for the life of the app. The only places the user can "go" are reachable via buttons on this panel (a UICollectionView). In case it matters, this app is landscape-only, and iOS 6-only.
In order to make this work I created a custom segue, which removes everything from the view except for the menu panel, then adds the new view controller's view as a subview, sets the new view's frame to the bounds of the superview, and sends the new view to the back (so it's behind the menu panel). I call viewWill/DidDisappear from prepareForSegue, because otherwise they don't get called.
It may sound kludgy (it does to me), but it works fine except for one thing - the new view comes up from the bottom. It looks funny.
I then tried adding my own animation block - I initially locate the view off to the left, then animate it into place. I send it to the back in the completion block for the animation. This seems perfectly logical, and the frame values are all what they should be. But this one is worse - the view comes in from the lower left corner.
Can anyone suggest a way to make this work? Here's my current perform method:
- (void)perform {
MainMenuViewController *sourceVC = (MainMenuViewController *)self.sourceViewController;
UIViewController *destinationVC = (UIViewController *)self.destinationViewController;
for (UIView *subview in [sourceVC.mainView subviews]) {
// don't remove the menu panel or the tab
if (![subview isKindOfClass:[UICollectionView class]] && [subview.gestureRecognizers count] == 0) {
[subview removeFromSuperview];
}
}
[sourceVC.mainView addSubview:destinationVC.view];
CGRect finalFrame = sourceVC.mainView.bounds;
CGRect frame = finalFrame;
frame.origin.x = finalFrame.origin.x - finalFrame.size.width;
destinationVC.view.frame = frame;
[UIView animateWithDuration:0.5 animations:^{
destinationVC.view.frame = finalFrame;
} completion:^(BOOL finished) {
// make sure it ends up behind the main menu panel
[sourceVC.mainView sendSubviewToBack:destinationVC.view];
}];
}
It turned out to be a simple error - I needed to set destinationVC's frame before calling addSubview. Setting it afterwards was triggering the unwanted animation.

Resources