SoundCloud: how to stop playing when hash change

…衆ロ難τιáo~ 提交于 2019-12-13 07:14:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!