Notified when a media player opens from UIWebView?

I have UIViewControllerin my application with UIWebViewin it. UIWebViewhas a fixed size and is configured to open any links in a new UIViewController(browser). This works, but when I try to click a video, such as YouTube or Vimeo, in a web view, it opens on top of the view controller. This is usually not a problem, but I have an overlapping view that should make the message go astray when that happens.

Is there a notification or some other way in which my view controller can receive a notification when the media player pops out UIWebView? I really need this to work better because it is really ugly as it is now.

Thank!

+5
source share
1 answer

From: http://www.alexcurylo.com/blog/2009/08/24/snippet-playing-youtube-videos/

Unfortunately, there is no direct control or notification of downloading, progress, logout, etc. However, you can get some indirect notifications based on the state of the application window: add to your view controller

[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(windowNowVisible:)
name:UIWindowDidBecomeVisibleNotification
object:self.view.window
];

[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(windowNowHidden:)
name:UIWindowDidBecomeHiddenNotification
object:self.view.window
];

to call them when the YouTube window is displayed and leaves accordingly.

- (void)windowNowVisible:(NSNotification *)notification
{
   NSLog(@"Youtube/ Media window appears");
}


- (void)windowNowHidden:(NSNotification *)notification 
{
   NSLog(@"Youtube/ Media window disappears."); 
}

and hey, if that's all you need, as a notice, you're good to go!

+21
source

All Articles