本文介绍了SoundCloud:哈希更改时如何停止播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用带有SoundCloud脚本的Ajax页面切换方法.
I'm using ajax page switching method with SoundCloud script.
当用户使用SoundCloud容器离开页面时如何停止播放音乐?
How to stop playing music when the user leaves the page with SoundCloud container?
我发现了这些问题:
// stop all players, might be useful, before replacing the player dynamically
$.scPlayer.stopAll = function() {
$('.sc-player.playing a.sc-pause').click();
};
当前,我在 .load
函数中调用初始化 $(.sc-player").scPlayer();
,但是我需要在哪里放置代码会在切换页面之前停止播放音频吗?
Currently I call initialization $(".sc-player").scPlayer();
inside .load
function, but where do I need the put the code which will stop playing audio before any page switching?
推荐答案
您可以添加事件监听器 window.onhashchange = stopAll;
you can add event listener window.onhashchange = stopAll;
并且stopAll()的定义将
and definition of stopAll() will be
stopAll = function(){$('.sc-player.playing a.sc-pause').click();};
这篇关于SoundCloud:哈希更改时如何停止播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!