嵌入 JavaScript?或者也许使用了其他一些技术?
首先,我想向您展示一段代码。该代码是将 YouTube 电影嵌入到您的网站的简单(旧式):
<object width="560" height="315">
<param name="movie" value="http://www.youtube.com/v/-pGYHDcQDwA?version=3&hl=da_DK"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/-pGYHDcQDwA?version=3&hl=da_DK" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed>
</object>
它非常简单并且有效。
我当前的解决方案
我还有一个视频播放器,它也允许嵌入。嵌入代码基本相同:
<object width="387" height="316" align="top">
<param name="movie" value="http://example.com/embedplayer.swf"></param>
<param name="salign" value="lt" /></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://example.com/embedplayer.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" salign="lt" width="387" height="316"></embed>
</object>
我的问题
我希望允许观看者在 iPad 或 iPhone 上观看我的视频。
文件格式不是问题,因为视频已被编码为几种所需的格式。
我想要的是具有与 YouTube 嵌入代码类似的功能。在 iPad/iPhone 上查看带有 YouTube 嵌入代码的页面时,会出现其他内容(我的猜测是带有正确文件格式链接的图像)。
当在 iPad/iPhone 上查看我自己的嵌入代码时,这显然不起作用,因为我直接链接到 SWF 文件。
我尝试过什么?
为了了解 YouTube 嵌入/对象的服务方式和内容,我只是尝试对嵌入代码中指定的 YouTube 网址执行一些简单的 GET 请求 (http://www.youtube.com/v/-pGYHDcQDwA?version=3&hl=da_DK ),这给了我大部分 404(因为错误的标头)或新的 HTML带有新 Flash 对象的源。
换句话说,我无法手动重现为 iPad/iPhone 提供的服务。
可能/替代解决方案
YouTube 还允许采用新的嵌入方法。
它看起来像这样:
<iframe width="560" height="315" src="http://www.youtube.com/embed/-pGYHDcQDwA" frameborder="0" allowfullscreen></iframe>
这对我来说非常透明。在 iframe 中嵌入另一个页面允许外部页面进行检查,从而向客户端提供正确的内容(HTML5、Flash 或其他内容)。没什么大不了的。
问题
- 这对于 YouTube 的旧嵌入代码有何作用?对我来说,使用 embed/object 标签应该嵌入某种指定的对象,但 YouTube 的嵌入代码似乎允许在 embed/object 元素中使用不同的内容。
- 新的(替代解决方案)是更好的方法吗?它看起来很灵活,并且可以方便将来的维护。但我总是听说 iframe 是禁忌。
Firstly, I'd like to show you a piece of code. The code is a simple (old style) of embedding a YouTube movie to your website:
<object width="560" height="315">
<param name="movie" value="http://www.youtube.com/v/-pGYHDcQDwA?version=3&hl=da_DK"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/-pGYHDcQDwA?version=3&hl=da_DK" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed>
</object>
It's pretty simple and works.
My current solution
I also have a video player, which allows for embedding also. The embed code is basically the same:
<object width="387" height="316" align="top">
<param name="movie" value="http://example.com/embedplayer.swf"></param>
<param name="salign" value="lt" /></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://example.com/embedplayer.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" salign="lt" width="387" height="316"></embed>
</object>
My Issue
I'd like to allow the viewer to see my videos on an iPad or iPhone.
File formats isn't the problem, as the vidoes has been encoded to several needed formats.
What I'd like is to have similar functionality as the YouTube embed code. When viewing a page with the YouTube embed code on a iPad/iPhone, something else appears (my guess is an image with a link to the correct file format).
When viewing my own embed code on an iPad/iPhone, this obviously doesn't work as I link directly to a SWF file.
What have I tried?
Trying to find out how and what the YouTube embed/object serves, I've simply tried doing some simple GET requests to the YouTube URL specified in the embed code ( http://www.youtube.com/v/-pGYHDcQDwA?version=3&hl=da_DK ) and this has given my mostly 404's (because of bad headers) or a new HTML source with a new Flash object.
In other words, I wasn't able to manually reproduce what is served for the iPad/iPhone.
A possible/alternative solution
YouTube also allows for a new method of embedding.
It looks like this:
<iframe width="560" height="315" src="http://www.youtube.com/embed/-pGYHDcQDwA" frameborder="0" allowfullscreen></iframe>
This is pretty transparent to me. Embedding another page in the iframe allows the external page to do the checks which allows serving the right content to the client (HTML5, Flash or something else). No big deal.
The questions
- How does this work for YouTube's old embed code? Using embed/object tags for me, should embed some sort of specified object, but it seems that YouTube's embed code allows for different content in the embed/object elements.
- Would the new (alternative solution) be a better way to do this? It seems flexible and allows for future easy maintanence. But I always hear that iframes is a no-no.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
他们使用服务器端脚本进行代理检测,并根据他们检测到的用户代理提供不同的内容。
They are using serverside scripts that do agent detection and serve up different content depending on what user agent they detect.
看来我看错了方向。
问题一:
在 iPhone/iPad 上使用嵌入代码测试其他视频网站给了我预期的结果 - 空白区域。
看来,通过Content Negotiation,设备浏览器能够替代对象/嵌入标签,其中包含在设备上启动 YouTube 应用程序所需的元素。
这意味着我无法创建类似的解决方案,这意味着我必须创建/使用 HTML5 视频播放器或使用带有 iframe 的替代解决方案(我可以将两者结合起来)。
这使得回答第二个问题变得多余,因为我没有其他选择。
It seems that I was looking in the wrong direction.
Question one:
Testing other video sites with embed codes on the iPhone/iPad gave me the result I expected - a blank area.
It seems that, through Content Negotiation, the device browser is able to replace the object/embed tags with the elements needed for starting the YouTube application on the device.
This implies that I cannot create a similar solution, which means I have to either create/use a HTML5 Video player or use the alternative solution with an iframe (I could combine the two).
This makes answering the second question redundant as I have no other alternatives.