3
votes

Playing youtube video as below:

videoView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 50, 300, 215)];
videoView.backgroundColor = [UIColor clearColor];
videoView.opaque = NO;
videoView.delegate = self;
[self.view addSubview:videoView];
NSURLRequest *loadRequest=[NSURLRequest requestWithURL:Your_Youtube_URL];
[videoView loadRequest:loadRequest];

Issue: Statusbar issue on UIWebView embedded YouTube video playback

Steps to produce Status bar issue:

  • When application orientation support is only Portrait.

  • User click to play video on UIWebview embedded youtube video player

  • Device open its default video player to play video and its provide landscape support to play video even if your application has only orientation support portrait

  • Now user change device orientation to landscape to view video in full screen 


  • Now user press Done button to stop video and come back to application

  • In this situation, status bar remain landscape and application screen looks in portrait mode.

1

1 Answers

4
votes

Solution:

- (void)viewDidLoad
{
…

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(VideoExitFullScreen:)
                                                 name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
                                               object:nil];

}

- (void)viewDidUnload
{

…

[[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
                                                  object:nil];
}

- (void)VideoExitFullScreen:(id)sender{

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];

}