问题
I'm using ajax page switching method with SoundCloud script.
How to stop playing music when the user leaves the page with SoundCloud container?
I've found these stokes:
// stop all players, might be useful, before replacing the player dynamically
$.scPlayer.stopAll = function() {
$('.sc-player.playing a.sc-pause').click();
};
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?
回答1:
you can add event listener window.onhashchange = stopAll;
and definition of stopAll() will be
stopAll = function() {
$('.sc-player.playing a.sc-pause').click();
};
来源:https://stackoverflow.com/questions/16378715/soundcloud-how-to-stop-playing-when-hash-change