iphone - 在 iPhone 上嵌入 YouTube 视频时出现问题

标签 iphone iframe uiwebview youtube

我尝试使用以下代码嵌入视频,以避免启动 YouTube 应用并留在我的应用中:

-(void)embedYouTube:(NSString*)url frame:(CGRect)frame {  

 NSString* embedHTML = @"<iframe type=\"text/html\" width=\"64\" height=\"39\" src=\"http://www.youtube.com/embed/j8Bc7eRTdWY\" frameborder=\"0\"></iframe>";
    if(videoView == nil) {          
        videoView = [[UIWebView alloc] initWithFrame:frame];  
        [movieDescView addSubview:videoView];  
    }  
    [videoView loadHTMLString:embedHTML baseURL:nil];  
}

问题是当我单击播放图标时,它会打开 YouTube 网站,其中我的 uiwebview 要求安装一些网络应用程序。我想阻止此网络应用程序弹出以全屏显示或启动视频。实际上,任何在不退出我的应用程序的情况下显示 YouTube 视频的解决方案都可以。

最佳答案

您可以使用它来加载电影(不需要生成 html 字符串):

movieView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 140, 100)];
movieView.delegate = self;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.youtube.com/embed/-h4zTEwgCpQ"]];
[movieView loadRequest:request];
[self.view addSubview:movieView];


#pragma mark -
#pragma mark UIWebViewDelegate
//To check if youtube try to show the overview page of m.youtube.com or the current movie
//if the user click on the youtube logo this method stop loading the mobile page
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSURL *urlRequest = [request URL];

    if ([[urlRequest absoluteString] isEqualToString:url]) {
        return YES;
    }

    return NO;
}

您唯一需要寻找的是使用“嵌入”链接。

关于iphone - 在 iPhone 上嵌入 YouTube 视频时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5136415/

相关文章:

iphone - 用户按下按钮后如何激活运动抖动?

javascript - 发布到 iframe 目标 : cannot get response from iframe

php - youtube iframe API 中的 playVideoAt() 函数不起作用

html - YouTube嵌入视频具有巨大的黑色边框

iphone - 如何在 iOS 6 上找到 UIWebView 工具栏(以替换它们)?

ios - webview后如何返回应用程序?

javascript - 在点击事件之前执行 stringByEvaluatingJavaScriptFromString

iphone - 我应该如何在 iOS 中动态创建表单?

iphone - iOS:路由器IP可达?

iphone - iOS 4.2.1 开发 SDK 中缺少 libXcodeDebuggerSupport.dylib