page player and ajax

  • Question
  • Updated 10 months ago
I use soundManager2 with page-player script, and I want to update my pages with AJAX. What is the right way to tell the script that the part of the page, which contains links to mp3-files, has been reloaded?
I tried this way:

function getAjaxResponse(){
...... //append received data to page

pagePlayer = null;
pagePlayer = new PagePlayer(null);
pagePlayer.initDOM();
}

but it doesn't work (I get error in pagePlayer.init(): oTiming has no properties)
Photo of

  • 3 Posts
  • 0 Reply Likes

Posted 7 years ago

  • 3
Photo of Scott

Scott, Official Rep

  • 3807 Posts
  • 246 Reply Likes
Official Response
Hi bhondu,

The script was designed to be created and run only once at page load etc., and as it modifies the DOM when it loads, would be non-trivial (time consuming) to modify to accept dynamic updates - eg., creating or removing elements on the fly. Unfortunately at this point even destroying and recreating an existing sound is tricky, as the JS inserts elements such as the control template (loading/progress bar, timing data etc.) into each LI when it runs.

You might be able to try calling pagePlayer.init() and modifying the counter it uses to be global, thus subsequent calls may find the new MP3 links and wouldn't conflict with old/existing ones. That is, adding onto the self.links[] array. You'd also need to modify pagePlayer.init() to not remove or clear the sm2_timing element innerHTML.

I'll consider adding a "refresh" method which will scan for new links or something, but bug fixes with the API are higher priority at this point. Thanks for the suggestion!