Webview playback control programmatically for YouTube video in iOS

好久不见. 提交于 2019-12-08 14:40:19

问题


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?


回答1:


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;
 }



回答2:


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
}



回答3:


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


来源:https://stackoverflow.com/questions/24825534/webview-playback-control-programmatically-for-youtube-video-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!