【发布时间】:2013-03-07 14:54:55
【问题描述】:
我正在尝试探索在 iOS 应用程序开发中我还能做些什么,而我刚刚尝试在我的应用程序中包含一个视频。
我在下面有这段代码,旨在在视图加载时播放 youtube 视频,但我得到的只是一个黑色的 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];
【问题讨论】:
-
你是在模拟器还是设备上试试这个?
-
@MikeD 我正在设备上测试它。
标签: ios objective-c uiwebview youtube-api