iOS 8 youtube 视频嵌入

标签 ios xcode uiwebview youtube

我遇到了我似乎无法理解的问题。

我有这段代码可以在 Xcode 5 和 iOS 7 中完美运行:

- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view, typically from a nib.
  CGFloat width = self.view.frame.size.width;
  CGFloat height = self.view.frame.size.height;
  UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
  NSString* embedHTML = @"\
  <html><head><meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; user-scalable=0;\"/>\
  <style type=\"text/css\">\
    body {\
    background-color: transparent;\
   color: black;\
  }\
  </style>\
  </head><body style=\"margin:0;\">\
  <embed id=\"yt\" src=\"https://www.youtube.com/v/M7lc1UVf-VE?hd=1\" type=\"application/x-shockwave-flash\" \
  width=\"%0.0f\" height=\"%0.0f\"></embed>\
  </body></html>";
  NSString *html = [NSString stringWithFormat:embedHTML, width, height];
  [webview loadHTMLString:html baseURL:nil];
  [self.view addSubview:webview];
}

当我在 Xcode 6 中为 iOS 8 构建相同的代码时,视频会显示在 webview 中,但是太小了。

任何人都可以解释这里发生了什么以及我如何克服这个问题吗?

最佳答案

我遇到了同样的问题,我用这个解决方案解决了

https://developers.google.com/youtube/v3/guides/ios_youtube_helper

同样在 YTPlayerView.m(~行:610)中试试这个改变:

[playerParams setValue:[NSString stringWithFormat: @"%0.00f", self.frame.size.height] forKey:@"height"];
// [playerParams setValue:@"100%" forKey:@"height"];
[playerParams setValue:[NSString stringWithFormat: @"%0.00f", self.frame.size.width] forKey:@"width"];
// [playerParams setValue:@"100%" forKey:@"width"];

希望对你有帮助

关于iOS 8 youtube 视频嵌入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25878439/

相关文章:

ios - NSURLProtocol + UIWebView + 某些域 = app UI frozen

ios - 在 iPhone 上使用 CADisplayLink 在 OpenGL ES View 中进行恒速旋转

ios - 在不使用 Segue 的情况下使按钮在单击时显示新 View ?

ios - 如何从 vector_float2 中提取单个值

xcode - 无法在我的 Mac 中的设备或模拟器上构建 flutter

iOS应用程序-本地html的存储方法

ios - 使用 AFNetworking 保存/缓存文件并将其用于在线和离线访问

iOS:在后台与核心数据自动同步

xcode - cocoapods安装卡在 “Updating local specs repositories”上

ios - 在 map View 之上添加 View