问题
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