在 iOS 应用中嵌入 YouTube 视频 [英] Embed youtube video in iOS App
本文介绍了在 iOS 应用中嵌入 YouTube 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在按下按钮时将 youtube 视频嵌入到网络查看器中.我有这个代码
I want to embed a youtube video into a webviewer whenever I press a button. I have this code
- (IBAction)testBtn:(id)sender {
NSString *code = @"<iframe width="560" height="315" src="//www.youtube.com/embed/1iBIcJFRLBA" frameborder="0" allowfullscreen></iframe>";
[[self youtubeWebPlayer]loadHTMLString:code baseURL:nil];
}
我的问题是,每当我按下按钮时,什么也没有发生.网络查看器保持空白.
My problem is, whenever I press the button nothing happens. The webviewer remains blank.
我在代码中放置了断点以仔细检查代码是否被我的应用调用并且确实被调用了.
I have put breakpoints in the code to double check that the code is called by my app and it is indeed called.
编辑***
我已经通过替换解决了这个问题
I have fixed the problem by replacing
[[self youtubeWebPlayer]loadHTMLString:code baseURL:nil];
与
[[self youtubeWebPlayer]loadHTMLString:code baseURL:[NSURL URLWithString:@"http://www.youtube.com"]];
推荐答案
试试这个,效果很好.您将 youtube 网址用作http://www.youtube.com/v/YOU_TUBE_VIDEO_ID".
Try this one this is working perfect. You use youtube Url as "http://www.youtube.com/v/YOU_TUBE_VIDEO_ID".
UIWebView * youTubeWebView=[[UIWebView alloc]initWithFrame:CGRectMake(0,0,320,320)];
youTubeWebView.allowsInlineMediaPlayback=YES;
youTubeWebView.mediaPlaybackRequiresUserAction=NO;
youTubeWebView.mediaPlaybackAllowsAirPlay=YES;
youTubeWebView.delegate=self;
youTubeWebView.scrollView.bounces=NO;
NSString *linkObj=@"http://www.youtube.com/v/1iBIcJFRLBA";//@"http://www.youtube.com/v/6MaSTM769Gk";
NSLog(@"linkObj1_________________%@",linkObj);
NSString *embedHTML = @"
<html><head>
<style type="text/css">
body {
background-color: transparent;color: white;}\</style>\</head><body style="margin:0">\<embed webkit-playsinline id="yt" src="%@" type="application/x-shockwave-flash" \width="320" height="320"></embed>\</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, linkObj];
[youTubeWebView loadHTMLString:html baseURL:nil];
[self.view addSubview:youTubeWebView];
这篇关于在 iOS 应用中嵌入 YouTube 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文