我正在尝试在 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”,但没有成功!
我尝试的最后一件事是如果视频以全屏模式播放,则添加一个侦听器,在 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”都没有被调用。
请帮忙!