UITextfield doesn't show keyboard after dismiss from presentMoviePlayerViewControllerAnimated - ios

I am working with an app which required to open "MPMoviePlayerViewController" when clicked on a video file.
There is a tabbarController into our app which has four Navigation controllers for four tabs.
My app only support portrait orientation, but video should support both landscape & portrait orientations. So, I make Subclass of "MPMoviePlayerViewController".
Code of that class..
#interface MyMovieViewController : MPMoviePlayerViewController
#end
#implementation MyMovieViewController
-(void)viewDidLoad{
[self setWantsFullScreenLayout:NO];
}
-(void)viewWillDisappear:(BOOL)animated{
[self resignFirstResponder];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
-(BOOL)shouldAutorotate{
return YES;
}
#end
In First tab, I show Gallery. There is a code to open video file.
UIGraphicsBeginImageContext(CGSizeMake(1,1));
MPMoviePlayerViewController * vc = [[MyMovieViewController alloc] initWithContentURL:[[[elcAsset asset] valueForProperty:ALAssetPropertyURLs] valueForKey:[[[[elcAsset asset] valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]]];
UIGraphicsEndImageContext();
// Remove the movie player view controller from the "playback did finish" notification observers
[[NSNotificationCenter defaultCenter] removeObserver:vc
name:MPMoviePlayerPlaybackDidFinishNotification
object:vc.moviePlayer];
// Register this class as an observer instead
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: #selector(doneButtonClick:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: vc.moviePlayer];
[self presentMoviePlayerViewControllerAnimated:vc];
[vc.moviePlayer prepareToPlay];
[vc.moviePlayer play];
Video is working file. It also support both orientations. but when I switch to another tab, then no textfield show keyboard when clicked on it.
Please help. Thanks is advance.

I have solved the issue.
Actually, MPMoviePlayerViewController support both orientations and my app support only portrait. When i dismiss MPMoviePlayerViewController,then parentview of it think that it is Landscape mode.
So, it display landscape keyboard, which's CGPoint is lower than screen. Thats why I am not able to see keyboard.
I have make write following code into my CustomNavigationController.
- (BOOL)shouldAutorotate
{
return [self.visibleViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.visibleViewController supportedInterfaceOrientations];
}
Now, it is working fine.

YOu need to dismiss Your MoviePlayer..
Use this notification that calls when your video is over
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.theMoviePlayer];
and write method of it.
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
[self dismissMoviePlayerViewControllerAnimated];
MPMoviePlayerController* theMovie = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
}

You can try this delegate method,
(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
[myTextField becomeFirstResponder];
return YES;
}
If this does not work, try to find out what is called after dismissing the view and then insert following code... This will definitely work.
[myTextField becomeFirstResponder];

Related

XCDYouTubeVideoPlayerViewController: Exit fullscreen when rotate to UIDeviceOrientationPortrait

I use XCDYouTubeKit library for my iOS project. I present video from nonFullScreen mode with code:
self.videoPlayer = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:self.youtubeID];
[self.videoPlayer presentInView:self.videoView];
[self.videoPlayer.moviePlayer play];
When iPhone rotate to landscape mode i set FullScreen video with catching rotate current ViewController:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if (fromInterfaceOrientation == UIDeviceOrientationPortrait) {
[self.videoPlayer.moviePlayer setFullscreen:YES animated:NO];
}
But how i can catch rotation XCDYouTubeVideoPlayerViewController in fullScreen video mode??
Thank
My decision
in this class i add in viewDidLoad observer
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(handleDidChangeStatusBarOrientationNotification:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
And execution
- (void)handleDidChangeStatusBarOrientationNotification:(NSNotification *)notification; {
if ([self.videoPlayer.moviePlayer isFullscreen] && [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) {
[self.videoPlayer.moviePlayer setFullscreen:NO animated:YES];
}
}
I think the easiest way to get this information is to subclass XCDYouTubeVideoPlayerViewController and override didRotateFromInterfaceOrientation: and/or viewWillTransitionToSize:withTransitionCoordinator:

Set orientation of MPMoviePlayerController

My whole application is in portrait mode only and i am playing youtube video in my application. For you tube I am using UIWebview. When user click on play button in UIWebview it automatically launch the MPMoviePlayerController. So I did not declared any MPMoviePlayerController object. So I want MPMoviePlayerController support both portrait and landscape orientation. So please suggest.
If you use NavigationController, you could subclass it and do the following:
#import "MainNavigationController.h"
#import <MediaPlayer/MediaPlayer.h>
#implementation MainNavigationController
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
if ([[[self.viewControllers lastObject] presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
{
return UIInterfaceOrientationMaskAll;
}
else
{
return UIInterfaceOrientationMaskPortrait;
}
}
#end
Then you should set your app to support all orientations, and this code will allow orientation change only if it is playing your movie 'MPMoviePlayerController`.
When calling your movie you should send a notification, so if user closes it in any orientation other than portraitit switches back to portrait.
Something like this:
- (IBAction)playButton:(id)sender {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackDidFinish)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.player.moviePlayer];
NSURL *url = [NSURL URLWithString:videoUrl];
self.player = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
self.player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[self presentMoviePlayerViewControllerAnimated:self.player];
}
-(void)moviePlaybackDidFinish
{
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:#"orientation"];
}
This should do it for you, let me know how it goes.

Enable UIButton after UIImagePicker is presented

I have tried everything or at least I think I have.
I am presenting a custom UIImagePicker with a shutter UIButton disable.
This UIButton is only enable when my view controller receives a notification telling that the camera is ready.
This method is being called; however, when I set the UIButton to enable nothing happen. The button is there because I can touch it but I cannot see it.
Here is a piece of code:
- (void)viewDidLoad
{
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(cameraIsReady:) name:AVCaptureSessionDidStartRunningNotification object:nil];
}
- (void)cameraIsReady:(NSNotificationCenter *)notigivation{
NSLog(#"Camera is ready");
[self.shutterButton setEnable:YES];
[self.shutterButton setNeedsDisplay]; //I tried with and without this method.
}

iOS 5 and above: enable landscape mode in MPMoviePlayerController

I have an application entirely in portrait mode. (iOS 5 and above)
I have a video played using MPMoviePlayerController, now in this video i want that when user rotates the iPhone, the video should go to landscape mode(in fullscreen).
When video ends , again the video should go into portrait mode.
Code:
-(void)PlayVideo:(NSURL*)videoUrl
{
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
[moviePlayerController.view setFrame:CGRectMake(6, 69, 309, 196)];
[self.view addSubview:moviePlayerController.view];
// moviePlayerController.fullscreen = YES;
moviePlayerController.controlStyle = MPMovieControlStyleNone;
[self.view bringSubviewToFront:self.shareView];
[self.view bringSubviewToFront:self.qualityView];
[moviePlayerController play];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
}
Rest of the app, i want in portrait only.
How do i achieve this?
First you need to set Support interface orientation to Portrait as well as Landscape
Now in every UIViewController you need to override these methods -
for iOS 5 -
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
for iOS 6
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
In UIViewController where you are going to add MPMoviePlayerController override -
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
I created Xcode project with sample of the video player. It can show video on full screen in landscape mode. You can download it . I hope it helps you.
And second. Instead of
[self.view bringSubviewToFront:self.shareView];
[self.view bringSubviewToFront:self.qualityView];
you should write like this:
[moviePlayerController.view insertSubview: self.shareView
atIndex: 2];
[moviePlayerController.view insertSubview: self.qualityView
atIndex: 2];
then shareView and qualityView appears on top of the movie player.

iPad MPMoviePlayerController - Disable Fullscreen

Is there a way to disable the fullscreen button of the MPMoviePlayerController ?
Just did it:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieEventFullscreenHandler:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieEventFullscreenHandler:)
name:MPMoviePlayerDidEnterFullscreenNotification
object:nil];
self.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
}
- (void)movieEventFullscreenHandler:(NSNotification*)notification {
[self.moviePlayer setFullscreen:NO animated:NO];
[self.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
}
Depending on your needs, you can also simply disable all user interactions on the player view.
player.view.userInteractionEnabled = NO;
You can set controlStyle to Fullscreen. these controls are somewhat different, but it doesn't feature a Fullscreen button!
[_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];
You could hide the playback controls and add your own custom ones, this will prevent the default buttons being rendered at all
I.e with
[player setMovieControlMode:MPMovieControlModeNone];
Unfortunately none of above worked for me properly, so picking the above I implemented the following (and worked fine):
Hide the full screen button.
Add this code in the method where you initialise the movie player.
....
//Because we have to wait until controllers are shown
[self performSelector:#selector(hideFullscreenButton) withObject:self afterDelay:0.5];
...
Add the methods:
-(void) hideFullscreenButton{
//Hide full screen mode button
[self hideFullscreenSubview:movieClip.view.subviews];
}
-(void) hideFullscreenSubview:(NSArray*)arr{
for(UIView *v in arr){
if([v.subviews count]>0)
[self hideFullscreenSubview:v.subviews];
else
NSLog(#"%#",v);
if(v.frame.origin.x==975 ){
v.hidden=TRUE;
}
}
}
The problem relies that there is no tag to identify which view you have to hide. In my case I figure it out by the view coordinates.
Overwrite tap gestures for do not allowing fullscreen zoom.
movieClip.controlStyle = MPMovieControlStyleEmbedded;
//Disable tap for not allowing that video control set on a full screen mode.
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action:#selector(doSingleTap)];
singleTap.numberOfTapsRequired = 1;
[movieClip.view addGestureRecognizer:singleTap];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action:#selector(doDoubleTap)];
doubleTap.numberOfTapsRequired = 2;
[movieClip.view addGestureRecognizer:doubleTap];
[singleTap requireGestureRecognizerToFail:doubleTap];
And add the selector methods:
-(void) doSingleTap{
//DO NOTHING!!!
}
-(void) doDoubleTap{
//DO NOTHING!!!
}
There's a cheat:
MPMoviePlayerController *mpc = (...some instance...)
UIView *fsbutton = [[mpc view] viewWithTag:512];
[fsbutton setHidden:YES];
The main catch is, you have to do it in viewDidAppear: or similar, because the MoviePlayer view sets itself up somewhere inside didMoveToWindow or didMoveToSuperview, which happen after viewWillAppear:. So you get a brief flash of the fullscreen button. Other obvious catches include: brittle vs. Apple changing that 512 tag value (although it works in 3.2 - 4.2); and of course Apple would rather you not do this.
The endorsed solution is to set the control style to MPMovieControlStyleNone and roll your own transport controls, which is more work.
No, there is no way. Hopefully with the next update.
in order to disable switch to full screen mode, either form button or pinch gesture, you can use this:
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.view.userInteractionEnabled =NO;
Wired does this. For the videos that start in fullscreen, they have the standard MPMoviePlayerController controls, but are missing the fullscreen buttons. And they're using the standard built-in ones, since they suddenly got an AirPlay button with 4.2.
Simple block to remove pinch zoom here
Hope it help
it work with me on iOS6
for (UIView *view in moviePlayer.view.subviews) {
for(UIPinchGestureRecognizer *pinch in view.gestureRecognizers){
if([pinch isKindOfClass:[UIPinchGestureRecognizer class]])
[view removeGestureRecognizer:pinch];
}
}
This worked on iOS 7, iPhone 5s.
Add Notification:
MPMoviePlayerDidEnterFullscreenNotification : #"moviePlayFullscreenNote:"
- (void)moviePlayFullscreenNote:(NSNotification*)notification
{
if (notification.object == self.videoPlayer)
{
[self.videoPlayer setFullscreen:NO animated:YES];
self.videoPlayer.controlStyle = MPMovieControlStyleEmbedded;
}
}
Notice that I only listen for "DID" and not the "WILL" notification as well as running it animated. I think this works as it gives the system time to react. When I used the "WILL" and "DID" as noted in answers above it led to a black screen with no controls. There is a slight glitch that is visible when the transition occurs, but I need the play/scrub buttons from embedded.
Fullscreen button along with pause button can be removed.
[self.videoPlayer setControlStyle:MPMovieControlStyleNone];
If the only thing you want to do is disable pinch to go full screen (i.e. keep interaction enabled and whatever control style you want), you can use this:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *set = [event allTouches];
NSArray *arr = [set allObjects];
for (int i = 0; i < arr.count; i++) {
UITouch *touch = (UITouch *) [arr objectAtIndex:i];
NSArray *recognisers = touch.gestureRecognizers;
for (UIGestureRecognizer *recogniser in recognisers) {
if (recogniser.enabled && [recogniser isMemberOfClass:[UIPinchGestureRecognizer class]]) {
recogniser.enabled = NO;
}
}
}
}
This is the Swift version of the first solution of Javier Calatrava Llavería:
func hideFullScreenButton() {
self.hideFullScreenSubview((self.moviePlayerController?.view.subviews)!)
}
func hideFullScreenSubview(subviews: [UIView]) {
for view: UIView in subviews {
if view.subviews.count > 0 {
self.hideFullScreenSubview(view.subviews)
}
if view.frame.origin.x == 631 {
view.hidden = true
}
}
}
And when the user taps on Play:
self.performSelector(#selector(VideoViewController.hideFullScreenButton), withObject: self, afterDelay: 0.5)
(VideoViewController is the view controller in which I have the MPMoviePlayerController)
I know, it's a little outdated, but anyway. I did some research in that direction, and looks like a found an answer. I do not know, why it's working, but it is.
-(void) playMovieAtURL: (NSURL*) theURL {
MPMoviePlayerController* theMovie =
[[MPMoviePlayerController alloc] initWithContentURL: theURL];
//That line is for ARC. Without it, it may not work.
self.moviePlayer = theMovie;
theMovie.scalingMode = MPMovieScalingModeAspectFill;
theMovie.controlStyle = MPMovieControlStyleFullscreen;
theMovie.repeatMode = MPMovieRepeatModeOne;
//Here you'd better use your custom ViewController subclass, if you want autorotating and all that stuff.
UIViewController * vc = [UIViewController new];
[vc.view addSubview:theMovie.view];
theMovie.fullscreen = YES;
theMovie.view.frame = vc.view.bounds;
vc.view = theMovie.view;
[self presentModalViewController:vc animated:YES];
theMovie.fullscreen = YES;
[theMovie prepareToPlay];
[theMovie play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
// When the movie is done, release the controller.
-(void) myMovieFinishedCallback: (NSNotification*) aNotification
{
[self dismissModalViewControllerAnimated:YES];
MPMoviePlayerController* theMovie = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver: self
name: MPMoviePlayerPlaybackDidFinishNotification
object: theMovie];
[self.moviePlayer.view removeFromSuperview];
self.moviePlayer = nil;
// Release the movie instance created in playMovieAtURL:
}
Put a UIView or UIButton with transparent background on top of the view that shows the video, so that the user won't be able to tap on the view that contains the video.

Resources