如何使音频文件和 Flash 播放器可嵌入?

发布于 2025-01-07 14:31:09 字数 1435 浏览 0 评论 0原文

我有一个播放音频文件的 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&amp;show_comments=true&amp;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&amp;show_comments=true&amp;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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷弦 2025-01-14 14:31:09

iframe 与对象

YouTube 使用 的主要原因(即“好处”)是它允许他们更改视频的实际显示方式 - 无需嵌入视频的网站必须更改其 元素。即:

  • YouTube 可以根据浏览器提供不同的内容 - 即,如果浏览器没有安装 FlashPlayer,它们可以在 中输出 HTML 5 元素改为。将来,您可能希望执行相同的操作(使用 元素),因此 可能是长期灵活性的不错选择 YouTube 可以根据浏览器

  • 在出现错误等情况下,YouTube 可以更轻松地更改内容的输出方式。换句话说,如果出于某种原因(例如,为了使 FlashPlayer 12 正常工作),他们需要添加或更改 < param> 在 HTML 或其他内容中,他们可以做到这一点,而无需每个嵌入视频的人都必须自己更改它。

代码

您可能会使用 Ruby 来输出实际的代码,尽管您也可以使用 Javascript - 它需要以某种方式生成,以便反映应该播放的确切音频。至于将其放在

 标签中,这不是技术上的必要性 - 只是为了更好的用户体验 - 只是因为更容易分辨代码的开始和结束位置。

到底使用哪些标签只是一个哲学问题。有些人会说“使用 元素(以指示它的代码)并将其样式设置为显示为块元素”;其他人会说“只是我们一个

 元素,因为它已经是一个块元素了”;有些人会说“将两者结合起来:
...

”。

跟踪

您可以跟踪其中任何一个。对音频的请求将始终发送到您的服务器,因此在任何一种情况下都可以使用跟踪。不过, 的情况更容易以与您已经执行的方式相同的方式进行跟踪 - 因为该 iframe 的 src 只是指向音频页面的简单版本(仅显示实际播放器),您可以按照与音频页面完全相同的方式增加 views_count

至于优点

为什么SoundCloud专门使用?只是在这里猜测...

要么他们还没有做到这一点,要么他们已经决定(在某些方面非常正确)完全可预测的、工作的 元素有点到了未来,现在还不值得。

或者他们对某些开发人员所拥有的 元素有一种哲学上的厌恶(我以某种方式包括在内 - 我只在绝对没有其他替代方案有意义的情况下才使用它)。

用户(即嵌入声音的人)也可能打算在 会造成麻烦且不直接支持的地方使用它( 另外,虽然我怀疑这是他们的原因,但这意味着

对他们的服务器的又一次打击 - 让用户嵌入 将直接检索 Flash 内容。如果他们使用 ,SoundCloud 将受到每个嵌入的额外请求 - 一个用于 HTML,一个用于音频文件(对于 FlashPlayer,一个用于 swf 文件)。

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 the src of that iframe will just be a link to a simpler version of your audio page (only showing the actual player), you can increase views_count in exactly the same way as in the audio page.

As for <object> advantages

Why 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文