监听webview视频播放、结束

#pragma mark Notification
- (void)addNotification
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(beginPlayVideo:)
                                                 name:UIWindowDidBecomeVisibleNotification
                                               object:self.view.window];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(endPlayVideo:)
                                                 name:UIWindowDidBecomeHiddenNotification
                                               object:self.view.window];
}
 
- (void)removeNotification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIWindowDidBecomeVisibleNotification
                                                  object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIWindowDidBecomeHiddenNotification
                                                  object:nil];
}
-(void)beginPlayVideo:(NSNotification *)notification{
    //如果是alertview或者actionsheet的话也会执行到这里,所以要判断一下
    if ([[UIApplication sharedApplication].keyWindow isMemberOfClass:[UIWindow class]]){
        [playButton removeFromSuperview];
    }
}
 
 
-(void)endPlayVideo:(NSNotification *)notification{
    NSLog(@"结束");
}

你可能感兴趣的:(监听webview视频播放、结束)