0

こんにちは、YouTube の URL を取得しました。ここで、HTML が埋め込まれた WebView にロードしています。すべて正常に動作しています。ビデオはポートレート モードで再生されます。問題は、ビデオがポートレートで再生されているときにデバイスを横向きに回転すると、ビデオが横向きモードで再生されないことです。みんなこれで私を助けてくれます。

   - (void)embedYouTube:(NSString*)url frame:(CGRect)frame {
        NSString* embedHTML = @"\
        <html><head>\
        <style type=\"text/css\">\
        body {\
            background-color: transparent;\
        color: white;\
        }\
        </style>\
        </head><body style=\"margin:0\">\
        <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
        width=\"%0.0f\" height=\"%0.0f\"></embed>\
        </body></html>";
        NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];
        if(webView == nil) {
            webView = [[UIWebView alloc] initWithFrame:frame];

        }
        [webView loadHTMLString:html baseURL:nil];
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [self embedYouTube:urlString frame:CGRectMake(0, 0, 320, 568)];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification object:nil];

    }


- (void)viewWillAppear:(BOOL)animated {
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation))
    {
        //I set my new frame origin and size here for this orientation
        isShowingLandscapeView = YES;
    }
    else if (deviceOrientation == UIDeviceOrientationPortrait)
    {
        //I set my new frame origin and size here for this orientation
        isShowingLandscapeView = NO;
    }
}

- (void)updateLandscapeView
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
    {
        //I set my new frame origin and size here for this orientation
        isShowingLandscapeView = YES;
    }
    else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
    {
        //I set my new frame origin and size here for this orientation
        isShowingLandscapeView = NO;
    }
}

- (void)orientationChanged:(NSNotification *)notification
{
    // We must add a delay here, otherwise we'll swap in the new view
    // too quickly and we'll get an animation glitch
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}




- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait || UIInterfaceOrientationIsLandscape(interfaceOrientation));
}

-(IBAction)onHome{
[self dismissModalViewControllerAnimated:YES];
}
4

0 に答える 0