OBJ -C-在UIWebView中嵌入YouTube视频?
我正在使用以下代码尝试并在我的应用程序(在UIWebView中)进行YouTube视频播放。由于某种原因,我的网络浏览量只是一个黑匣子,而没有视频播放。
请参见下文:
dashboardViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
NSString *videoURL = @"https://youtu.be/8QrCPihtBSc";
UIWebView *videoView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.howtoView.frame.size.width, self.howtoView.frame.size.height)];
self.howtoView.backgroundColor = [UIColor whiteColor];
self.howtoView.opaque = NO;
self.howtoView.delegate = self;
[self.howtoView 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];
I'm using the below code to try and have a youtube video play inside my app (in a UIWebView). For some reason, my WebView returns as just a black box, and no video plays.
See below:
DashboardViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
NSString *videoURL = @"https://youtu.be/8QrCPihtBSc";
UIWebView *videoView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.howtoView.frame.size.width, self.howtoView.frame.size.height)];
self.howtoView.backgroundColor = [UIColor whiteColor];
self.howtoView.opaque = NO;
self.howtoView.delegate = self;
[self.howtoView 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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
embed
按钮,可以为您提供所需的代码。embed
button on youtube web page, that gives you required code.