Webview playback control programmatically for YouT

2019-06-09 12:09发布

In My App, User can open YouTube from UIWebview, I got notification when plays video in full screen, but I can't get control programmatically like mpmovieplayer controller to pause, play, stop.

How can I get it in webview?

3条回答
疯言疯语
2楼-- · 2019-06-09 12:40
NSURL *websiteUrl = [NSURL URLWithString:@"Link of Youtube Video"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:websiteUrl];
[myWebView loadRequest:urlRequest]; 
查看更多
Explosion°爆炸
3楼-- · 2019-06-09 12:44

Whenever you want to stop the music load the "" url to web view. So it will stop.

This is the code:

   [_Music_WbView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: [NSString stringWithFormat:@""]]]];
    _Music_WbView.hidden = YES;
   if([_Music_WbView retainCount] > 0)
 {
      [_Music_WbView release];
      _Music_WbView = nil;
 }
查看更多
相关推荐>>
4楼-- · 2019-06-09 12:46

In viewDidLoad

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

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

and for catch the full screen

#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
}
查看更多
登录 后发表回答