无论 HTML 网站中的 URL 或 URL 都播放音乐吗?

发布于 2024-11-17 01:05:49 字数 368 浏览 3 评论 0原文

我知道您可以打开一个单独的窗口,使用 Flash 或框架 (yuk) 来显示 mp3 播放器,无论您在哪个页面上,该播放器都会持续播放音频。但我刚刚在这里看到这个网站,它似乎没有框架、Flash 或单独的窗口,我想知道他们是如何做到的?

http://www.killertracks.com/#/browse.aspx

看起来他们'我正在使用 JavaScript 加载歌曲,但每当我访问网站中的不同 URL 时,音乐就会继续播放。我有什么想法可以做到这一点吗?我目前正在构建一个需要此功能的网站。

谢谢,

奥苏

I know you can either open a separate window, use Flash or frames (yuk) to display an mp3 player that continually plays audio regardless of which page you're on. But I've just seen this site here that appears to do it without frames, Flash or a separate window and was wondering how they do it?

http://www.killertracks.com/#/browse.aspx

Looks like they're using JavaScript to load the songs, but evern when I got to a different URL in the site, the music keeps playing. Any ideas how I could do that? Got a site I'm building at the moment that needs this featured.

Thanks,

Osu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

北方。的韩爷 2024-11-24 01:05:49

实际上,音频正在 Flash 播放器中播放:-)

但是,在播放音频时,所有页面均通过 AJAX 并通过片段标识符进行导航。

您可以在 Chrome 中看到这一点,例如,按 F12,选择“网络”选项卡,然后单击链接。如果列出了 themed-playlists.aspx,请单击它,然后在 Request Headers 部分中您将看到 X-Requested-With: XMLHttpRequest 这是 JavaScript 用于加载新页面的 API动态地无需导航离开当前页面。然后,新页面用于更新当前页面上的内容,使其看起来像新页面。许多网站使用这种机制来动态更新页面,而无需加载整个页面。

例如,当我输入这个答案时,JavaScript 会定期将我的答案发送到 stackoverflow 服务器并将其保存为草稿。这对于我与主页的交互是完全透明的。

使用此方法的另一个很棒的网站是 BBC Music Showcase,但是它动态播放两种音频视频,同时允许您浏览网站!

Actually the audio is being played in a Flash player :-)

However, while the audio is playing all pages are loaded via AJAX and made navigable via the Fragment Identifier.

You can see this in Chrome, for example, by pressing F12, selecting the Network tab, then clicking on a link. If there is a themed-playlists.aspx listed, click on it and in the Request Headers section you will see X-Requested-With:XMLHttpRequest which is the API that JavaScript is using to load the new page dynamically without navigating away from the current page. The new page is then used to update the content on the current page to make it look like the new page. Many websites use this mechanism to dynamically update a page without a full page load.

For example, as I am typing this answer, JavaScript is periodically sending my answer to the stackoverflow server and saving it as a draft. This is completely transparent to my interaction with the main page.

Another great site that uses this method is the BBC Music Showcase, however it dynamically plays both audio and video whilst allowing you to navigate the site!

等风来 2024-11-24 01:05:49

您可以使用 html5 来做到这一点,您可以直接在 javascript 中访问音频 api。

例如。

var sound = new Audio("file.mp3"); 
sound.play(); 

例如,请参阅这样的文章:http://www.storiesinflight.com/jsfft/visualizer/index.html

所以基本上你会在 javascript 中捕获按钮/链接事件并运行 javascript 代码,例如这是为了播放声音。虽然仅适用于 html5 浏览器,但大多数现代浏览器都支持它:) - 对于不支持的浏览器,也许您可​​以下载当前的 swf 音频播放器(使用这些播放器您可以使用提供的 javascript api 触发声音)。

You can do this with html5, you can access the audio api directly in javascript.

eg.

var sound = new Audio("file.mp3"); 
sound.play(); 

See an article like this for example: http://www.storiesinflight.com/jsfft/visualizer/index.html

So basically you would be capturing the button/link event in javascript and running javascript code like this to play the sound. Only works with html5 browsers tho, but most modern browsers support it :) - for browsers that dont support maybe you can download the swf audio players currently out there (with these can you trigger sounds using javascript apis provided).

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