我正在尝试探索在iOS应用程序开发中我还能做些什么,而现在我试图在我的应用程序中添加一个视频.
我有下面的代码,旨在播放YouTube视频加载视频,但我得到的只是一个黑色的webView.
Nsstring *videoURL = @"http://youtu.be/Wq_CtkKrt1o";
videoView = [[UIWebView alloc] initWithFrame:CGRectMake(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";
尝试这个你的问题会解决