我有一个webview控件并在Youtube中请求一些搜索。 有很多结果视频。 用户单击其中一个。 如何播放视频网址?
答案 0 :(得分:0)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemBecameCurrent:)
name:@"AVPlayerItemBecameCurrentNotification"
object:nil];
- (void)playerItemBecameCurrent:(NSNotification*)notification
{
AVPlayerItem *playerItem = [notification object];
if(playerItem == nil) return;
// Break down the AVPlayerItem to get to the path
AVURLAsset *asset = (AVURLAsset*)[playerItem asset];
NSURL *url = [asset URL]; // this is URL you need
}
答案 1 :(得分:0)
如果您只想获取网址,请尝试以下代码:
NSString * currentURL = [webView stringByEvaluatingJavaScriptFromString:@" window.location"];
但是,如果你想获得所有事件,只需使用webview委托方法:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *URLString = [[request URL] absoluteString];
//now you have the url;
return YES;
}