I am having trouble capturing when the YouTube player enters full screen mode or exits full screen mode in iOS 8 because these notifications were deleted by UIMoviePlayerControllerDidEnterFullscreenNotification and UIMoviePlayerControllerWillExitFullscreenNotification for this OS version.
Since my application project is installed only in portrait mode, the video will not rotate in landscape mode when it is playing, which is really not very convenient for watching video on your device.
Typically, the user wants to watch the video in portrait mode or landscape mode when the video enters full screen mode.
This is how I did it for iOS 7 , which worked fine, but not in iOS 8.
First I will install this function in my AppDelegate.m with a boolean property in my AppDelegate.h , which I called videoIsInFullscreen and function,
// this in the AppDelegate.h @property (nonatomic) BOOL videoIsInFullscreen; // This in my AppDelegate.m to allow landscape mode when the boolean property is set to yes/true. - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ if(self.videoIsInFullscreen == YES) { return UIInterfaceOrientationMaskAllButUpsideDown; } else { return UIInterfaceOrientationMaskPortrait; } }
Then in my ViewController.m First I would #import "AppDelegate.h" do this, add some notifications to my viewDidLoad method.
-(void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerStarted) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerEnded) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil]; }
Of course, do not forget to delete them.
-(void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil]; }
Then I had my functions, which will receive a call when these notifications receive fires ... This is where I enable landscape mode, and then return to the portrait. This is the case with my application, because it is configured only for portrait support, but I do not want this for a YouTube video.
But this does not apply to iOS 8 .. These notifications no longer work for iOS 8, so I found something similar using these notifications, but I'm not too happy because they are not 100% accurate for the video player. UIWindowDidBecomeVisibleNotification and UIWindowDidBecomeHiddenNotification So, how can I do it right or at least work correctly for the embedded YouTube video and enable landscape mode in iOS 8 ...?