Я пытаюсь воспроизвести видео YouTube на UIWebView, как показано ниже:
// 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];
Страница YouTube показывает, что когда я нажимаю на видео, оно начинает воспроизводиться, но не вращается.
Я провел неделю в поисках другого решения, внедрив «shouldAutorotate» и «supportedInterfaceOrientations», но безуспешно!
Последнее, что я пробовал, это добавить прослушиватель, если видео воспроизводится в полноэкранном режиме, в AppDelegate.m я добавил в «didFinishLaunchingWithOptions» код ниже:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
И реализовано:
- (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; }
Проблема в том, что ни «moviePlayerWillEnterFullscreenNotification», ни «moviePlayerWillExitFullscreenNotification» не вызываются.
Помогите, пожалуйста!