在webView中加载时如何在Movie Player中完成按钮操作?

时间:2012-08-30 10:37:50

标签: iphone

我是Iphone的新手并试图在webView中播放视频。所以,我需要完成按钮操作。请帮助我。

2 个答案:

答案 0 :(得分:0)

如果视频是在UIWebView中播放的,那么您可以在播放视频时使用以及使用以下代码按下完成按钮以及用于在webview中加载网址的代码时访问

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

可以通过

访问它
BOOL isVideoInFullScreenMode;//Temperory added here.. must be in .h file or at teh top if required
-(void)videoPlayStarted:(NSNotification *)notification{
//Your stuff here
   isVideoInFullScreenMode = YES;
}

-(void)videoPlayFinished:(NSNotification *)notification{
    //Your stuffs here
    isVideoInFullScreenMode = NO;
}

答案 1 :(得分:0)

最后我找到了完成按钮操作的解决方案...这个逻辑适用于ipad和amp; iPhone也.. 我使用UIGestureRecognizer解决了这个问题。

这是我的代码。

首先,我使用

添加EnterFullScreen的通知
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];

现在在youTubeStarted方法中我添加了此代码..

-(void)youTubeStarted:(NSNotification *)notification{
if (!tapRecognizer1) {
    tapRecognizer1 = [[UITapGestureRecognizer alloc] init];
    tapRecognizer1.delegate = self;
    [tapRecognizer1 setNumberOfTapsRequired:1];
    [self.view addGestureRecognizer:tapRecognizer1];
}    
}

这会将TapRecognizer添加到电影播放器​​中。

现在,以下委托方法将检查是否已完成按钮

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
NSLog(@"%@",touch.description);
NSString *ViewName = touch.description ;
CGPoint location = [touch locationInView:touch.view];
NSLog(@"location x===%f , location y=== %f",location.x,location.y);
NSRange Check = [ViewName rangeOfString:@"UINavigationButton"];
NSRange checkFrameOfButton;
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
   checkFrameOfButton = [ViewName rangeOfString:@"frame = (7 7; 50 30)"];
    if (checkFrameOfButton.length <= 0) {
        checkFrameOfButton = [ViewName rangeOfString:@"frame = (7 7; 51 30)"];
    } 
}
else {
    checkFrameOfButton = [ViewName rangeOfString:@"frame = (5 7; 48 30)"];
    if (Check.length<=0) {
        Check = [ViewName rangeOfString:@"UIView"];
    }
}
if (location.y<40 && location.x<85 && Check.length>0 && checkFrameOfButton.length>0) {
    [self endplaying];  
    }
    return YES;
}

现在在终端播放方法中你可以做你想做的......

相关问题