iOS 8 youtube视频嵌入

ber*_*ner 10 youtube xcode uiwebview ios

我面临的问题似乎无法理解.

我有这个代码在iOS 7的Xcode 5中完美运行:

- (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];
}
Run Code Online (Sandbox Code Playgroud)

当我在iOS 8的Xcode 6中构建相同的代码时,视频显示在webview中,但是很小.

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

小智 5

我有同样的问题,我解决使用这个解决方案

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

也可以在YTPlayerView.m(~line: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"];
Run Code Online (Sandbox Code Playgroud)

希望这有帮助