我正在尝试在我的应用中播放YouTube视频。好像我到了正确的地方,但视频没有播放。我在实际设备上运行应用程序(不在模拟器上)。
这是我正在使用的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *htmlString = @"<html><head>\
<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 320\"/></head>\
<body style=\"background:#000;margin-top:0px;margin-left:0px\">\
<iframe id=\"ytplayer\" type=\"text/html\" width=\"320\" height=\"240\"\
src=\"http://www.youtube.com/embed/VIDEO_ID&feature?autoplay=1\"\
frameborder=\"0\"/>\
</body></html>";
//VIDEO_ID holds the video embedded code I get from YouTube
[self.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]];
}
YouTube播放器正在加载,但当我点击“播放”按钮时,我收到“此视频目前无法使用”:
我测试了嵌入式视频ID(复制并粘贴到网页中)并找到相关视频(即我假设我有正确的视频ID)。
任何人都知道我做错了什么?
答案 0 :(得分:1)
我遇到了同样的问题,因为我在网络视图中使用了自定义用户代理,因此youtube没有提供正确的视频。
答案 1 :(得分:0)
您的问题是您正在使用的网址:
http://www.youtube.com/embed/VIDEO_ID&feature?autoplay=1
应该是:
http://www.youtube.com/embed/VIDEO_ID?feature&autoplay=1
这是因为网址本身是http://www.youtube.com/embed/VIDEO_ID
,参数是feature和autoplay = 1.
干杯 的Morten