Change Orientation for Youtube Videos ONLY - ios

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.

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)

How can I tell when UIImagePickerController is done switching cameras?

I am encountering an issue where if I try to take a picture with UIImagePickerController immediately after switching the cameraDevice from back to front camera or vice versa I get an error:
UIImagePickerController: ignoring request to take picture; camera is changing modes.
I have tried subscribing to the AVCaptureSession* events from NSNotificationCenter, but none of the capture session ready notifications are fired when the camera device changes. Is there a way to determine that the camera is ready again after switching cameras in UIImagePickerController?
Check out the code below:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(cameraIsReady:)
AVCaptureSessionInterruptionEndedNotification object:nil];
You would use this to kick off the code you want once the cameras are ready.
If you post your code, I can come back and edit in further help for you.

How hide or close my app when i reveive a call?

I have a little bug. I'm developing an iOS App.
If i receive a call, my app stays open and the screen for my entering call appears on my app. I would like to close my app if i have a call.
How can i fix that?
Thanks,
J.
The green, in-call status bar is not a bug but a feature. You don't need to close the app when the call comes.
Instead, make sure your views are resized properly when the in-call status bar appears.
As Per Apple Human Interface guidelines
Never quit an iOS app programmatically because people tend to interpret this as a crash.
However, if external circumstances prevent your app from functioning as intended, you need
to tell your users about the situation and explain what they can do about it. Depending on
how severe the app malfunction is, you have two choices.
Display an attractive screen that describes the problem and suggests a correction. A
screen provides feedback that reassures users that there’s nothing wrong with your app. It
puts users in control, letting them decide whether they want to take corrective action and
continue using your app or press the Home button and open a different app
If only some of your app's features are unavailable, display either a screen or an alert
when people use the feature. Display the alert only when people try to access the feature
that isn’t functioning. `
But again you handle your app accordingly when call comes by using the following notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(incomingCall:) name:CTCallStateIncoming object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(callEnded:) name:CTCallStateDisconnected object:nil];
Srinivasan N's answer has the incorrect observer, you'll want to add this observer which will account for all scenarios: phone calls, Personal Hotspot, GPS/navigation, etc.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(adjustViews:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
}
- (void)adjustViews:(NSNotification *)notification
{
NSValue *rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
CGRect newFrame;
[rectValue getValue:&newFrame];
NSLog(#"Changed frame to: Width: %f, Height: %f", newFrame.size.width, newFrame.size.height);
// Adjust your views here
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

Howto hide UIPopoverController when UIWebView plays a fullscreen youtube movie?

Please see the picture. After pressing the fullscreen button, the webview maximizes behind the UIPopover.
I tried to look out for MPMoviePlayerDidEnterFullscreenNotification, no luck.
I really don't want to ship my own UIPopoverController but this is my only "solution" at the moment. Using anything other than UIWebView is also not an option, as I am displaying YouTube-Movies.
Edit: I use a UIWebView, so there is no way to access the views/classes that are used internally.
According to this answer you can listen for UIMoviePlayerControllerDidEnterFullscreenNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeStarted:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(youTubeFinished:) name:#"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];

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

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

Resources