使 YouTube 视频自动播放
我需要帮助。我已经尝试这个好几天了。我需要将 Youtube 视频集成到我的 iPhone 应用程序中(不退出应用程序)。问题是我知道如何嵌入视频。但我需要自动运行视频而不显示缩略图。
我的代码显示缩略图视图,单击它后视频开始播放。但我需要的是自动播放视频(不先显示缩略图视图)。
我见过许多应用程序已经做到了这一点,但我无法在我的应用程序中实现它。
这是我的代码,你能告诉我哪里出了问题以及如何修复它吗?
我还添加了参数 autoplay
,但它仍然不起作用。
注意:我已经见过具有此功能的应用程序:)
NSString *html = @"<html><head> <meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head> <body style=\"background:#F00;margin-top:0px;margin-left:0px\"> <param name=\"movie\" value=\"http://www.youtube.com/embed/VO6FQ62Vip4\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"autoplay\" value=\"1\"></param><embed src=\"http://www.youtube.com/embed/VO6FQ62Vip4\" type=\"application/x-shockwave-flash\" width=\"560\" height=\"315\" allowfullscreen=\"true\" autoplay=1></embed></body></html>";
[webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://www.youtube.com/embed/VO6FQ62Vip4"]];
[self.view addSubview:webView];
I need help. I have been trying this for days now. I need to integrate a Youtube video to my iPhone application (without exiting the application). The thing is that i know how to embed the video. but i need to autorun the video without showing the thumbnail.
My code shows a thumbnail view, and after i click it the video starts to play. But what i need is to play the video automatically (without displaying the thumbnail view first).
I have seen many application that has done this, but i am unable to implement it in my application.
Here's my code, can you tell me what is wrong, and how to fix it.
I have also included the parameter autoplay
still its not working.
note: I have already seen apps that has this feature :)
NSString *html = @"<html><head> <meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head> <body style=\"background:#F00;margin-top:0px;margin-left:0px\"> <param name=\"movie\" value=\"http://www.youtube.com/embed/VO6FQ62Vip4\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"autoplay\" value=\"1\"></param><embed src=\"http://www.youtube.com/embed/VO6FQ62Vip4\" type=\"application/x-shockwave-flash\" width=\"560\" height=\"315\" allowfullscreen=\"true\" autoplay=1></embed></body></html>";
[webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://www.youtube.com/embed/VO6FQ62Vip4"]];
[self.view addSubview:webView];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要找到 UIWebView 内部的播放按钮并向其发送 UIEventTouchUpInside 操作。
you need to find the play button that is inside the UIWebView and send it UIEventTouchUpInside action.
所以我的 html 看起来像这样
,我制作了 jQuery 代码来添加自动播放 youtube 视频所需的变量,因此,一旦用户粘贴 youtube 嵌入代码,它就会立即使视频自动播放。
So my html looked like
and I made jQuery code to add the variables that are required to autoplay youtube video so, once user paste the youtube embed code, it right away makes the video autoplay.