How to know when Youtube player/plugin on iPad goes fullscreen? - ipad

Is there any way to know when the Youtube player/plugin on iPad goes fullscreen?
I have a UIWebview being displayed inside a Modal view controller that contains a Youtube video. If the user choose to view the Youtube video in fullscreen mode, it's displayed in fullscreen (naturally), but behind the UIWebview's modal view.
I'd like to know if some Notification or Delegate message is sent when the video starts to play in fullscreen mode, so that I would be able dismiss my modal view controller (or bring the Youtube fullscreen video to front in some way).
Thanks in advance.

I think the best way is to :
1°) Know it by JS (because it's inside the UIWebView), like adding a click() event on the youtube object.
2°) Do an JS action and caught it with the UIWebViewDelegate
Maybe there is a better solution.
Good Luck !

For anyone interested, I found an alternative workaround for this.
I created a custom UIView inherited class for the view containing the webview. Responding to the (BOOL)pointInside event, if the touch event took place within coordinates of YouTube's 'fullscreen' button on the bottom right, I passed a notification to trigger a dismissal of the modalviewcontroller.
A little ugly, but it works for me!

As per #prabhu-natarajan
in ViewDidLoad add the following code
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(VideoExitFullScreen:) name:#"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(VideoEnterFullScreen:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
The following methods are for showing the message/functions for respective process of entering/exiting to/from full screen
- (void)VideoExitFullScreen:(id)sender{
// Your respective content/function for Exit from full screen
}
- (void)VideoEnterFullScreen:(id)sender{
// Your respective content/function for Enter to full screen
}
From : This link

Related

How to detect when a user exits the YouTube Player view on iOS?

When using the YouTube helper library for iOS, I want to be able to detect the change of state when a user exits the player to stop playback. I've tried to use kYTPlayerStateEnded but that only triggers after the video has reached the end.
After looking through the YTPlayerView.m file, I can't seem to find a state that will achieve this. Is there another means of detecting when you've pressed 'Done' and exited the player view?
What do you mean "exits the player?" Do you mean when the user pauses this video or if the user exits the full screen player?
For leaving full the screen player, you can use the UIWindowDidBecomeVisibleNotification notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoExitFullScreen:) name:UIWindowDidBecomeVisibleNotification object:self.view.window];
For detecting pauses, you can listen for the YTPlayerState kYTPlayerStatePaused in the state change callback:
- (void)playerView:(YTPlayerView *)playerView didChangeToState:(YTPlayerState)state;
If your YTPlayerView is a subview of a UIViewController, you can use viewWillDisappear: on the view controller to clean up your player.
To get around the issue you are describing you can use a notification with UIWindow.didBecomeHiddenNotification (Swift). This should be placed in the view controller where you are playing the video.
NotificationCenter.default.addObserver(self, selector: #selector(playerExited), name: UIWindow.didBecomeHiddenNotification, object: nil)

Change Orientation for Youtube Videos ONLY

I currently have my iPhone application orientation set to Portrait only and was wondering if it were possible to change the orientation of a Youtube video, since it comes up in its own modal view controller?
I have a UIWebView that has a youtube video in there and when clicking it, it brings up the youtube/apple media player in a modal view controller. Is it possible to only change the orientation of this video player, to three orientations, and then reset it back to portrait once it is done?
I noticed in another post that these two help see if the movie player is active and inactive but I have not figured out how to change the orientation and then reset it. Any guidance and help is appreciated in advance. Thanks!
Code that is used to check for Movie Player start/finish
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeStarted:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeFinished:) name:#"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
Does anyone know how to control or grab the UIMoviePlayerController? Maybe there is someway to intercept it and control its orientation.

Weird behavior with button near notification center pulldown on iPad

I've got a UIButton (the 'back button') in the upper left corner of an iPad application that dismisses a view controller. I've discovered that if you tap this button slightly too high, you can both activate the button and start to pull down the notifications pane at the same time. When this happens, my -viewWillDisappear gets executed and stops the animations in the view, but the view doesn't actually dismiss. Of course, the notifications pane doesn't come down all the way, so the net result looks like my animations crashed, and that the back button failed as well.
The obvious solution would be to just move the button down a little bit, but as that is undesirable for layout reasons, I'm curious if:
Anyone has ever seen this behavior before.
If it's well-defined behavior, and if so where does Apple describe it.
Are there any known work-arounds?
EDIT: actually looks like less of an issue after all. Turns out it's my -applicationWillResignActive that's getting called, not -viewWillDisappear. Still looks bad, but at least the behavior is well defined. I'm not activating my home button at all, just pulling down the notifications pane.
I have done an UIViewController which has a timed animation (like a banner ad) going on, and bringing the notification pane down does not stop it until the pane is fully disclosured.
Maybe you have to deal with your animations on -applicationWillResignActive: and -applicationDidBecomeActive:, like pausing and resuming them.
You can receive those notifications directly on your UIViewController (instead of dealing with them on you AppDelegate) by adding the following code to your -viewDidLoad:
// Add observers
[[NSNotificationCenter defaultCenter]addObserver:self
selector:#selector(pauseAnimations:)
name: UIApplicationWillResignActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self
selector:#selector(resumeAnimations:)
name:UIApplicationDidBecomeActiveNotification
object:nil];

Keep ios keyboard open

I have a ios app that launch a UIWebView and you can interact with this web (the app is like a container). In the interaction with the web you need the keyboard a lot. So, I want (if it's possible) to keep the keyboard always open.
I've found some solutions, but none of them work for me.
I've tried with:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
and I able to detect when the keyboard are going to hide, but I don't know what I can do in keyboardDidHide method to avoid the keyboard to be closed.
I've tried also with:
webView.keyboardDisplayRequiresUserAction
But nothing happens.
Do you know how I can do this?
Thanks!
You can try playing with UIViewController's disablesAutomaticKeyboardDismissal property. Try overriding this property and returning NO.

How to take a photo on the volume-up event when using UIImagePickerController with custom camera controls?

In iOS 5, the volume-up button will now take a photo in the camera app, and on a UIImagePickerController instance where .showsCameraControlls == YES. Happy days.
However, when I set showsCameraControlls to NO, and supply my own (which in turn triggers takePicture method), the volume-up button will no longer work. How can I detect the volume event while the UIImagePickerController is showing?
The old way to detect volume changes was like so:
AudioSessionSetActive(true);
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(volumeChanged:)
name:#"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
I added this code to my application delegate. Strangely volumeChanged: is not triggered until after I show the UIImagePickerController for the first time. More importantly, it isn't triggered while the UIImagePickerController is visible (nor is the usual volume HUD shown), I guess since Apple disabled it & hijacked the event.
So once again, is there any way to detect the volume-up button event, while the UIImagePickerController is being displayed, when using custom camera controls, for the purpose of taking a photo?
If you're wondering why I need to use custom camera controls, it is because I want the ability to take multiple photos, which the standard camera controls do not allow.
On iOS 8 you can add an observer to the notification _UIApplicationVolumeUpButtonDownNotification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(volumeChanged:)
name:#"_UIApplicationVolumeUpButtonDownNotification"
object:nil];
If you are using UIImagePickerController, I was able to capture the event and use it to call TakePicture with a custom view.
On top of that, UIImagePickerController ensures that pressing volume up won't change the volume.
I'm not sure if Apple would approve an app listening to that notification; this seems to be the cleanest approach.
Try using the AVCapture APIs instead of UIImagePicker. Here's a tutorial:
http://www.musicalgeometry.com/?p=1273
It's a lot lower level and it's harder to use, but it shouldn't block the volume controls.
You might also want to try a trick like playing a silent audio file to enable the volume controls during image capture.
Update: I also found this tutorial on using the volume button for camera shutter:
http://ios.biomsoft.com/2011/12/07/taking-control-of-the-volume-buttons-on-ios-like-camera/

Resources