Going through paid mail is what I implemented to determine if the YouTube / Safari window is on. My application is really simple, and it has only the main window, and the YouTube / Safari view is loading.
viewDidLoad:
activeWindow = [[UIApplication sharedApplication] keyWindow]; windowTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(checkForMedia) userInfo:nil repeats:YES]; - (void) checkForMedia{ newWindow = [[UIApplication sharedApplication] keyWindow]; if(newWindow == activeWindow){ NSLog(@"media is not playing"); }else{ NSLog(@"media is playing"); } }
source share