I m trying to play a YouTube video on UIWebView as bellow :
// Create the URL
_videoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.youtube.com/watch?v=%@", _videoID]];
// Create the request with the URL
NSURLRequest *requestObj = [NSURLRequest requestWithURL:_videoUrl];
// Load the request into the Web View
[_webView loadRequest:requestObj];
The youtube page shows, when I clique on the video it starts to play, but it didn't rotate.
I spent on week now looking for different solution, by implementing "shouldAutorotate" and "supportedInterfaceOrientations", without success !
The last thing I tried is to add a listener if the video is playing in fullscreen mode, in AppDelegate.m I added to "didFinishLaunchingWithOptions" the code bellow :
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
And implemented :
- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
self.allowRotation = YES; }
- (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
self.allowRotation = NO; }
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (self.forceLandscapeRight) {
return UIInterfaceOrientationMaskLandscapeRight;
}
if (self.allowRotation) {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
return UIInterfaceOrientationMaskPortrait; }
The problem is that neither "moviePlayerWillEnterFullscreenNotification" or "moviePlayerWillExitFullscreenNotification" are called.
Help please!