如何使音频文件和 Flash 播放器可嵌入?
我有一个播放音频文件的 Flash 播放器(使用 JWPlayer)。该文件播放正常。
如何提供嵌入代码供最终用户复制,以便他们可以发布播放器并直接在自己的网站上播放音频文件?我应该在某处使用 HTML
标签吗?或者 JavaScript 生成嵌入代码/链接?
例如。 SoundCloud 有:
<object height="81" width="100%"> <param name="movie" value="https://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F31988157&show_comments=true&auto_play=false"></param> <param name="allowscriptaccess" value="always"></param> <embed allowscriptaccess="always" height="81" src="https://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F31988157&show_comments=true&auto_play=false" type="application/x-shockwave-flash" width="100%"></embed> </object> <span><a href="http://soundcloud.com/chris_ilett/the-fray">The Fray</a> by <a href="http://soundcloud.com/chris_ilett">chris_ilett</a></span>
YouTube 有:
<iframe width="420" height="315" src="http://www.youtube.com/embed/FL7yD-0pqZg" frameborder="0" allowfullscreen></iframe>
拥有
最后,在主站点上。每当最终用户访问音频页面时。网络应用增加了views_count
。如果我使用
I've got a flash player (using JWPlayer) that plays an audio file. The file plays fine.
How do I provide the embed code for end-users to copy, so they can post the player and play the audio file on their own site directly? Should I be using HTML <pre>
tags somewhere? Or JavaScript to generate the embed code / link?
For example. SoundCloud has:
<object height="81" width="100%"> <param name="movie" value="https://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F31988157&show_comments=true&auto_play=false"></param> <param name="allowscriptaccess" value="always"></param> <embed allowscriptaccess="always" height="81" src="https://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F31988157&show_comments=true&auto_play=false" type="application/x-shockwave-flash" width="100%"></embed> </object> <span><a href="http://soundcloud.com/chris_ilett/the-fray">The Fray</a> by <a href="http://soundcloud.com/chris_ilett">chris_ilett</a></span>
And YouTube has:
<iframe width="420" height="315" src="http://www.youtube.com/embed/FL7yD-0pqZg" frameborder="0" allowfullscreen></iframe>
What are the benefits of having an <object>
and an <iframe>
?
Lastly, on the main site. Any time an end-users visits the audio page. The web app increases the views_count
. If I am using <object>
or <iframe>
. Will I still be able to track the number of views somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iframe 与对象
YouTube 使用
的主要原因(即“好处”)是它允许他们更改视频的实际显示方式 - 无需嵌入视频的网站必须更改其
元素。即:
YouTube 可以根据浏览器提供不同的内容 - 即,如果浏览器没有安装 FlashPlayer,它们可以在
中输出 HTML 5
。将来,您可能希望执行相同的操作(使用元素改为
元素),因此
可能是长期灵活性的不错选择 YouTube 可以根据浏览器
在出现错误等情况下,YouTube 可以更轻松地更改内容的输出方式。换句话说,如果出于某种原因(例如,为了使 FlashPlayer 12 正常工作),他们需要添加或更改
< param>
在 HTML 或其他内容中,他们可以做到这一点,而无需每个嵌入视频的人都必须自己更改它。代码
您可能会使用 Ruby 来输出实际的代码,尽管您也可以使用 Javascript - 它需要以某种方式生成,以便反映应该播放的确切音频。至于将其放在
到底使用哪些标签只是一个哲学问题。有些人会说“使用
元素(以指示它的代码)并将其样式设置为显示为块元素”;其他人会说“只是我们一个
iframe vs object
The main reason for YouTube's use of
<iframe>
(i.e. "the benefit") is that it allows them to change how the video is actually displayed - without the website that's embedding the video having to change its<object>
element. I.e.:YouTube can serve different content depending on the browser - i.e., if the browser doesn't have FlashPlayer installed, they could output an HTML 5
<video>
element in the<iframe>
instead. In the future, you might want to do the same (with an<audio>
element), so<iframe>
might be a good choice for flexibility in the long term.It's easier for YouTube to change how the content is output in case of bugs etc. In other words, if for some reason (to mak FlashPlayer 12 behave, for example) they need to add or change a
<param>
in the HTML or something else, they can do that without every person embedding their videos having to change it themselves.The code
You would probably use Ruby to output the actual code, although you could use Javascript too - it would need to be generated somehow in order to reflect the exact audio that's supposed to be played. As for putting it in
<pre>
tags, it's not a technical necessity - just a matter of a better user experience - simply because it's easier to tell where the code starts and ends.Which tags to use exactly is just a matter of philosophy. Some would say "use a
<code>
element (to indicate it's code) and style it to display as a block element"; others would say "just us a<pre>
element since it's already a block element"; and some would say "Combine the two:<pre><code>...</code></pre>
".Tracking
You can track either. The requests for the audio will always be sent to your server, so it's possible to use tracking in either case. The case of
<iframe>
is easier to track in the same way you're already doing it, though - since thesrc
of that iframe will just be a link to a simpler version of your audio page (only showing the actual player), you can increaseviews_count
in exactly the same way as in the audio page.As for
<object>
advantagesWhy does SoundCloud use
<object>
exclusively? Just guessing here...Either they just haven't gotten to it yet, or they've decided (quite rightly in some regards) that a completely predictable, working
<audio>
element is a bit into the future, and not worth it just yet.Or they have that philosophical dislike of the
<iframe>
element that some developers have (me included in some ways - I only use it if absolutely no other alternative makes sense).The user (i.e., the one who's embedding the sound) may also intend to use it in a place where
<iframe>
would cause troubles, isn't directly supported (e.g. some CMS's) etc.Also, although I doubt it's their reason, it means one more hit to their server - letting users embed
<object>
will retrieve the flash content directly. If they use<iframe>
, SoundCloud will be hit by an additional request per embed - one for the HTML and one for the audio file (and, for FlashPlayer, one for the swf file).