Objective-C:在App上播放Youtube视频 [英] Objective-C: Play Youtube Video on App
本文介绍了Objective-C:在App上播放Youtube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试探索iOS应用程序开发中还能做些什么,现在我尝试在我的应用程序中添加视频。
I am trying to explore what else can i do in iOS app development and it just now that i've tried to include a video on my app.
I下面有这个代码,目的是在视图加载时播放YouTube视频,但我得到的只是一个黑色的webView。
I have this code below that aims to play a youtube video when the view loads, but all i got is just a black webView.
NSString *videoURL = @"http://youtu.be/Wq_CtkKrt1o";
videoView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
videoView.backgroundColor = [UIColor clearColor];
videoView.opaque = NO;
videoView.delegate = self;
[self.view addSubview:videoView];
NSString *videoHTML = [NSString stringWithFormat:@"\
<html>\
<head>\
<style type=\"text/css\">\
iframe {position:absolute; top:50%%; margin-top:-130px;}\
body {background-color:#000; margin:0;}\
</style>\
</head>\
<body>\
<iframe width=\"100%%\" height=\"240px\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>\
</body>\
</html>", videoURL];
[videoView loadHTMLString:videoHTML baseURL:nil];
推荐答案
你必须使用嵌入链接
使用以下代码
NSString *videoURL = @"http://www.youtube.com/embed/Wq_CtkKrt1o";
而不是
NSString *videoURL = @"http://youtu.be/Wq_CtkKrt1o";
试试这个你的问题会解决
try this your problem will solve
这篇关于Objective-C:在App上播放Youtube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文