Screen blackout when performing Pinch Gesture on MPMoviePlayerController - ios

I have this strange issue in iOS4 where in the Video which is playing in MPMoviePlayerController blacks out when the user performs certain kind of gestures over the screen. I'm simply creating a UIViewController and object for MPMoviePlayerController and then setting the View onto the UIViewController.
I want to ask if this issue is solvable or not, and whats the correct way of playing a streaming video on iPhone.
And if there is way that I can use a overlay view over MPMoviePlayerController and capture all gestures and pass on single taps or touches to MPMoviePlayerController for general functionality of MPMoviePlayerController and avoiding Gestures that is causing the issue.
Please help me solving the problem with the Best possible solution and please help me in elaborating the solution.

Apple embedded UIPinchGestureRecognizer in MPMoviePlayerViewController, but it can't be found in UIResponder.gestures property.
You can disable UIPinchGestureRecognizer embedded in touchesBegan method of MPMoviePlayerViewController.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
NSArray *array = touch.gestureRecognizers;
for (UIGestureRecognizer *gesture in array) {
if (gesture.enabled && [gesture isMemberOfClass:[UIPinchGestureRecognizer class]]) {
gesture.enabled = NO;
}
}
}
}

I had a similar problem and I just found the reason of my problem from the Apple's doc:
When you add a movie player’s view to your app’s view hierarchy, be sure to size the frame correctly, as shown here:
...
[player.view setFrame: myView.bounds]; // player's frame must match parent's
...
Now my pinches are not crashing my app.

I saw this issue and found a simple workaround.
The above gesture-nuking trick could not be used as we do not want to use MPMoviePlayerViewController (we have some custom controls when the video is not in fullscreen and would like to keep the smooth transition).
Symptoms (iOS 5.1):
When the user repeatedly opened a video in fullscreen, pinched it back out of fullscreen and then did the same with a new video the screen would go black the 5th time a video was started and entered fullscreen.
While the screen is blacked out it is possible to hide and show the status bar by single tapping, but no video or navigation bar appears.
Using the "Done" button in fullscreen instead of pinch it was possible to close fullscreen without any problems ever.
We allocate a fresh MPMoviePlayerController for each video and don't leak anything. This did not help.
Workaround:
When dismissing the view which had the MPMoviePlayerController view in it we set contentURL = nil on the player.
After that we have no problems with black screen on subsequent MPMoviePlayerController instances.
It seems there is some internal cleanup which is performed when using the "Done" button, but not when pinching to close fullscreen.

I hate this issue. What I have been able to find is that having full screen mode needs to have embedded control in order for the NSNotificationCenter to respond with the correct Notification. Sounds stupid and ridiculous, but this is what i've found in 4.0.

Related

UIWindow + lockscreen issue

straight to the point: Our app has UITableView with UITableViewCell that has AVPlayerViewController inside (its view) + custom video controls. One of the controls is fullscreen mode. Note that everything works perfectly - loading video, reusing, even the fullscreen.
Fullscreen functionality is based on creating new UIWindow, setting its rootViewController to the videoplayer and making it keyAndVisible - basically showing fullscreen AVPlayerViewController from cell subview on tap
The issue comes when user locks his device - after unlocking, the fullscreen window "disappears" and app is frozen / stuck on previous screen (the list with video cell, text cells.. - the one that made the new UIWindow)
The UIWindow (video window) is there, but without content (no subviews, VCs..) on top of the main (app, tableview list..) UIWindow - refer to pictures.
This issue is not happening on Simulator - only real devices.
View hierarchy debug before locking the device and showing the video on fullscreen (with new UIWindow):
View hierarchy debug after unlocking the device and app freezing on previous UIWindow:
Is there any possible fix? Or a better way of presenting AVPlayerViewController from UITableViewCell (while playing and without stopping the video)?
Note: the bug happens even if we remove landscape / portrait orientation changing, the issue seems to be related to UIWindow
PS: sorry for hiding the names in the pictures - NDA...

How to stop 3d touch its interrupt other touch events?

I have a view with touchesMoved event in current UIViewController , when touch move in screen it will draw something (free draw)
then I add a subView in the view and bind the UITapGestureRecognizer(set numberOfTapsRequired 2) with subview,
If double click is detect I will move the UIImageView to the click position.
When I try to draw again, something wrong is happen, the draw line is not smooth now (some line is not display)
Because of the 3D Touch in iPhone6s and 6s Plus, So I can't detect the tapCount in touchesEnded.What Shall I do?
The best way is stop the 3d touch while your app is launched :
As per the apple documentation you can see this here :Apple Docs
A user can turn off 3D Touch while your app is running, so read this property as part of your implementation of the traitCollectionDidChange: delegate method.
To ensure that all your users can access your app’s features, branch your code depending on whether 3D Touch is available. When it is available, take advantage of 3D Touch capabilities. When it is not available, provide alternatives such as by employing touch and hold, implemented with the UILongPressGestureRecognizer class.
Refer to iOS Human Interface Guidelines for ideas on how to enhance your app’s interactions for users with 3D Touch-capable devices while not leaving your other users behind.
BEST CODE:
#interface ViewController () <UIViewControllerPreviewingDelegate>
#property (nonatomic, strong) UILongPressGestureRecognizer *longPress;
For backward compatibility I’ll also add a long press gesture recogniser here. Should our sample app be run on a device without 3D Touch support, at least the preview can be brought up via a long press gesture.
We’ll check if 3D Touch is available using something like the following method. To complete the setup, I’ve also included a custom initialiser for the long press gesture.
- (void)check3DTouch {
// register for 3D Touch (if available)
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
[self registerForPreviewingWithDelegate:(id)self sourceView:self.view];
NSLog(#"3D Touch is available! Hurra!");
// no need for our alternative anymore
self.longPress.enabled = NO;
} else {
NSLog(#"3D Touch is not available on this device. Sniff!");
// handle a 3D Touch alternative (long gesture recognizer)
self.longPress.enabled = YES;
}
}
- (UILongPressGestureRecognizer *)longPress {
if (!_longPress) {
_longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:#selector(showPeek)];
[self.view addGestureRecognizer:_longPress];
}
return _longPress;
}

UIView Animation Freezes

I'm implementing drag-keyboard dismissal (like in the iPhone Messages app) manually because UIScrollViewKeyboardDismissModeInteractive doesn't seem to work with a text view inside a toolbar above the keyboard.
It works in portraint mode, but in landscape orientation, sometimes when I animate the toolbar (which is actually just a UIView) & keyboard, they freeze. But, they did animate because I checked using breakpoints that the animation code ran and when I tap on the screen where they're supposed to be, I get the correct reactions (like keyboard keys pop up, etc.).
I'm using the old style of animations beginAnimations:context: because this is how to mimic the keyboard animation in iOS 7.
This seems like an iOS SDK bug. How do I fix this?
I was sometimes (when the pan velocity was large) using UIViewAnimationCurveLinear instead of the curve from the keyboard notification's userInfo. I took that condition out so that I always use the curve from the keyboard notification's userInfo and things seem to be working fine now.

UIWebView: Media Player Rotates View Controller

I'm encountering an issue while using a webview. My app is currently a portrait application, but when a media player loads in a webview within my app, the user can rotate the player, which rotates my view controller as well. I know I can get a notification for when the player comes up and disappears, but is there a way to prevent it from rotating the controller in the first place?
It doesn't seem like anyone has an answer. I have all of the standard "don't rotate unless if I tell you to" methods and plist values, but its still rotating. Its only when I load up a webview and the media player loads over it. If I rotate my device, the media player rotates along with it, which feels natural, but when I go back to the webview view controller, its rotated, which isn't good.
Add this key in your info.plist :
UISupportedInterfaceOrientations and set it to UIInterfaceOrientationPortrait
Ok, this a blind shot. I've used this trick to force the system to adjust to the required orientation, add this lines when the webview will appears, or when the player will disappear:
UIViewController *viewController = [[UIViewController alloc] init];
[self presentModalViewController:viewController animated:NO];
[self dismissModalViewControllerAnimated:NO];
Try in some of those methods, or in the didAppear or didDisappear if dosen't work. I know it look like rubbish, but sometimes works.
There doesn't seem to be a correct answer to this question.

MPMoviePlayerController done button, Landscape orientation

I'm using simple MPMoviePlayerController. In portrait mode it is emmbedded into my layout. When I rotate my device I want it to go full screen. In full screen mode there is a done button but only thing it does is pausing the video. I want to dismiss modal view controller when the done button is tapped. How can I do this?
I've tried:
Putting a [UIColor clearColor] on a background of a button and place a button over Done button thus intercept touch event into my own selector. It failed because my custom button isn't displayed when MPMoviePlayerController is in fullscreen mode.
Going to notification center and trying to catch "willExitFullscreen" but it won't occur (pressing done button when in landscape fullscreen mode isn't goint out from the fullscreen mode).
Finding done button in the MPMoviePlayerController... but I was unable to find it.
Using MPMoviePlayerViewController isn't an option as I want to be able to use embedded player in my controller when i Portrait mode, and be able to rotate movie without loading it from scratch (so pushing new controller when user changes device orientation isn't right solution for me).
I've read a few topics on this issue and question can be the same or similar but anserws require either things I've checked (i.e. notifications) or things I can't use (MPMoviePlayerViewController).
ANSWER (as I am unable to post it in 7h)
Heh ok..
The culprit of this whole mess was this line of code
[self.mpPlayer setControlStyle:MPMovieControlStyleFullscreen];
So it seems that setting Fullscreen control style when going into fullscreen mode will break done button....
Makes no sense to me. But when I commented out this line I am able to recive willExitFullscreen notification and I can work with that.
The culprit of this whole mess was this line of code
[self.mpPlayer setControlStyle:MPMovieControlStyleFullscreen];
So it seems that setting Fullscreen control style when going into fullscreen mode will break done button....
Makes no sense to me. But when I commented out this line I am able to recive willExitFullscreen notification and I can work with that.

Resources