【问题标题】:Cannot start embedded Youtube video by tapping the play button using UIWebView无法通过使用 UIWebView 点击播放按钮来启动嵌入的 Youtube 视频
【发布时间】:2014-11-26 00:56:54
【问题描述】:

我在 iOS 上的 UIWebView 中嵌入了一个 Youtube 视频,到目前为止它工作正常。显示视频“海报框架”,其顶部有正常的红色播放按钮。点击播放按钮只会点击播放按钮外部的任何地方开始播放视频。我首先认为这是与 iOS 8 相关的问题,但同样的问题也发生在 iOS 7(模拟器)上。这真的很烦人,因为我们的用户自然会点击播放按钮而它什么也没做。

有谁知道 Youtube 是否更改了可能导致此问题的某些内容?

这是我用于在应用中显示视频的代码:

NSString* urlString = [NSString stringWithFormat:@"http://www.youtube.com/embed/%@", videoId];
NSMutableString* html = [[[NSMutableString alloc] initWithCapacity:1] autorelease];
[html appendString:@"<html><head>"];
[html appendString:@"<style type=\"text/css\">"];
[html appendString:@"body {"];
[html appendString:@"background-color: transparent;"];
[html appendString:@"color: white;"];
[html appendString:@"}"];
[html appendString:@"</style>"];
[html appendString:@"</head><body style=\"margin:0\">"];
[html appendFormat:@"<iframe class='youtube-player' type='text/html' width='%0.0f' height='%0.0f' src='%@' frameborder='0'></iframe>", frame.size.width, frame.size.height, urlString];
[html appendString:@"</body></html>"];

NSLog(@"Opening HTML: %@", html);
videoView2 = [[UIWebView alloc] initWithFrame:frame];
[videoView2 setMediaPlaybackRequiresUserAction:NO];
[videoView2 loadHTMLString:html baseURL:nil];
...

【问题讨论】:

  • 请注意,标准的 Youtube 嵌入代码也会发生这种情况。我刚接到一个客户的电话来解决这个问题。

标签: ios uiwebview youtube


【解决方案1】:

我也遇到过这个问题,似乎有一个涉及“控件”YouTube 播放器参数的解决方法。如果设置“controls=0”(默认为“controls=1”),红色的播放按钮是可点击的。我不太喜欢这个解决方案,因为它显然隐藏了控件,但它确实允许点击红色播放按钮。

【讨论】:

    猜你喜欢
    • 2017-02-22
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    • 2012-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    相关资源
    最近更新 更多