iOS 8 YouTube视频嵌入

编程入门 行业动态 更新时间:2024-10-14 18:17:09
本文介绍了iOS 8 YouTube视频嵌入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

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=\"www.youtube/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]; }

当我在适用于iOS 8的Xcode 6中构建相同的代码时,视频将显示在Web视图中,但尺寸很小.

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

developers.google/youtube/v3/guides/ios_youtube_helper

还可以在YTPlayerView.m(〜行: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视频嵌入

本文发布于:2023-11-05 18:40:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561570.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视频   iOS   YouTube

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!