5

I have got a UIViewController in my app with a UIWebView in it. The UIWebView is fixed-size and configured to open any links in a new UIViewController (browser). This works, but when I try clicking a video like YouTube or Vimeo from within the web view, it opens on top of the view controller. This would normally not be a problem, but I have an overlapping view that needs to get a message to move out of the way when this happens.

Is there a notification or any other way my view controller can get notified when a media player pops out of the UIWebView? I really need this to work better, because it's really ugly the way it currently is.

Thanks!

jszumski
  • 7,430
  • 11
  • 40
  • 53
Emil
  • 7,220
  • 17
  • 76
  • 135

1 Answers1

21

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

Unfortunately, there’s no kind of direct control or notifications of loading, progress, quitting, etc. However, you can get some indirect notifications based on your application’s window state: add in 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 get these called when the YouTube window is shown and goes away respectively.

- (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 require by way of notification you’re good!

peterp
  • 3,145
  • 1
  • 20
  • 24
  • I actually just needed that, just to let me know when to move other objects out of the way! Thanks a lot! :) (I'll keep the question open for a couple of days, though.) – Emil Jun 21 '11 at 22:00
  • This works for youtube-videos but not vimeo! Could it have something to do with HTML5? (still the correct answer, accepting and rewarding bounty :)) – Emil Jun 24 '11 at 13:03
  • Urgh, must be, are you embedding the video yourself? – peterp Jun 24 '11 at 13:30
  • If so, then you could probably figure out when playback stops/ starts using JavaScript, and then communicate back to your app: http://stackoverflow.com/questions/1662473/how-to-call-objective-c-from-javascript – peterp Jun 24 '11 at 13:32
  • No, it's embedded via vimeo's oEmbed-javascript class: http://www.vimeo.com/api/docs/oembed – Emil Jun 24 '11 at 17:53
  • When I do this, the windowNowVisible notification appears to be called both when the youtube video opens and when it closes? (get same log message each time) – shim Jul 22 '13 at 02:36