在iOS中以编程方式为YouTube视频播放Webview播放控件

时间:2014-07-18 12:52:56

标签: ios uiwebview youtube

在我的应用程序中,用户可以从UIWebview打开YouTube,我在全屏播放视频时收到通知,但我无法通过编程方式控制mpmovieplayer控制器暂停,播放,停止。

如何在webview中获取它?

3 个答案:

答案 0 :(得分:1)

每当你想要停止音乐加载时,""网址视图的网址。所以它会停止。

这是代码:

   [_Music_WbView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: [NSString stringWithFormat:@""]]]];
    _Music_WbView.hidden = YES;
   if([_Music_WbView retainCount] > 0)
 {
      [_Music_WbView release];
      _Music_WbView = nil;
 }

答案 1 :(得分:0)

在viewDidLoad

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

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

并抓住全屏

#pragma mark - UIMoviePlayerController notification handle

- (void)VideoExitFullScreen:(id)sender{
NSLog(@"Exit from Full Screen..");
}

- (void)VideoEnterFullScreen:(id)sender {
   NSLog(@"Enter in Full Screen..");
   [web goBack];  //back to notmal webview.. or pause the video
}

答案 2 :(得分:0)

NSURL *websiteUrl = [NSURL URLWithString:@"Link of Youtube Video"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:websiteUrl];
[myWebView loadRequest:urlRequest];