即使在更改页面时也能继续播放音乐 [英] Continuing music playback even while changing pages

查看:36
本文介绍了即使在更改页面时也能继续播放音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SoundCloud 是一个出色的网站,它使用了 HTML5 和 Backbone.js.唯一的问题是,我找不到他们使用什么技术可以让音乐在换页时继续播放.

SoundCloud is an amazing site that makes use of HTML5 and Backbone.js. The only thing is, I can't find what technology they use that allows the music to keep playing even while changing pages.

他们使用什么技术来播放音频流?

What technology are they using to get the audio stream playing?

推荐答案

事实是,您没有加载新页面,但内容是通过 AJAX 加载的.

The fact is, that you do not load a new page, but the content is loaded via AJAX.

页面然后使用 HTML5 History API 添加使用浏览器的后退和前进按钮导航的可能性.

The page then uses the HTML5 History API to add the possibility to Navigate using the browser's backward and forward buttons.

我通过阅读和尝试以下两个资源开始研究这个主题:

I started into this topic by reading and trying out the following two resources:

http://diveintohtml5.info/history.html
http://html5demos.com/history

最简单的方法是通过AJAX加载替换当前内容,然后调用

The most simple way is to load and replace the current content via AJAX and then call

history.pushState(null, null, link.href);

为了添加当前显示页面的历史条目.

In order to add the history entry of the currently shown page.

如果您现在按下后退按钮,浏览器将不会加载上一页,而是触发事件 popState.这可用于使用 AJAX 或存储在 JavaScript 变量中的信息恢复上一页.

If you now press the back button, the browser won't load the previous page, but fire the event popState. This can be used to restore the previous page using AJAX or information stored in your JavaScript variables.

window.addEventListener("popstate", function(e) {
    //loadPreviousPage();
}

这篇关于即使在更改页面时也能继续播放音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆