iOS 8 youtube 视频嵌入 [英] iOS 8 youtube video embed

查看:21
本文介绍了iOS 8 youtube 视频嵌入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm facing problems that I can't seem to understand.

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

I have this code that works perfectly in Xcode 5 with 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 中,但很小.

When I build the same code in Xcode 6 for iOS 8 then the video displays in the webview but is way to small.

谁能解释一下这里发生了什么以及我如何克服这个问题?

Can anybody explain what's happening here and how I could overcome this?

推荐答案

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

I had the same problem, I solve using this solution

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

也在 YTPlayerView.m (~line: 610) 中尝试此更改:

also in the YTPlayerView.m (~line: 610) try this changes:

[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 视频嵌入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆