私は次のように UIWebView で YouTube ビデオを再生しようとしています:
// 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」を実装することで、別の解決策を探すのに1週間を費やしましたが、成功しませんでした!
最後に試したのは、ビデオがフルスクリーン モードで再生されている場合にリスナーを追加することです。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」が呼び出されないことです。
助けてください!