tags:

views:

13

answers:

2

Hi there, I apologise in advance if my question seems a bit misleading, but I'm trying to wrap my head around this one.

I have a flash-based MP3 player (http://blog.lacymorrow.com/projects/xspf-jukebox) that exposes a Javascript API that is really handy for my situation. I am using jQuery and swfObject to embed the Flash player and that works well.

Now the player has auto-resume and auto-play functions that cause it to immediately start playing when the page is loaded, which is great. However, what I am trying to do is STOP the player when a certain page is browsed to. For instance, when I browse to contact.html, I want the player to stop playing any music. I had thought that the following would work:

$(function($) {
  window.document.myJukebox.stopTrack();
}); 

I then remembered that everything inside $(document).ready() or $(function($) {}) will execute as soon as the DOM is loaded BUT before all page contents are loaded. What I need to do is ensure that the above script runs without any user intervention once the entire page is fully loaded --> this is what I am stuck with and need your help with, please. If I have the following hyperlink on the page:

<a id="player-stop" href="javascript:window.document.myJukebox.stopTrack();">Click to Stop</a>

and click it, then the player does stop, so its clear to me that I need to have something that runs automatically without the user having to click on a STOP button. I have tried running this in a script at the bottom of the page with no luck.

Thank you!

+1  A: 

I'm guessing the first one does not work because the DOM is actually ready, but the Flash content is not at that time.

maartenba
yeah, I guess I'm trying to find a way using jQuery to gain access to the flash player's Javascript API once **it** has been loaded.
Shalan
+1  A: 

Try using setTimeout to schedule execution of your stop function later. If you have some sort of property on myJukebox that tells if player is playing or not, you can use setInterval and make it clear itself when it actually stops the player.

Also, it is worth investigating if player has some sort of startPlaying event and stop it after it fired the startPlaying event.

Alex Reitbort
Hi alex, thanks for your reply. Unfortunately `setTimeout` does not work, and the source code is unavailable for me to have a look thru. do you have any other suggestions?
Shalan
What do you mean does not work? What timeout did you set? Did you try to increase it?
Alex Reitbort
OKAY!!! it does work :) But I had to place the script at the bottom of the page in order for it to work - runs after 5 secs. My concern is - what happens to people with slow internet connections.
Shalan
here's what Im thinking...as a workaround, but going the `setTimeout` route, maybe I can run some kind of `blockUI` action of certain parts of the page to prevent user interaction on that until the player STOP function is run. what do u think? :)
Shalan
Actually Alex, your recommendation to use `setTimeout` helps me sort out a much bigger issue regarding the player on certain other pages...its the player's *shuffle* function that is causing me grief - unfortunately its a requirement by my client. So What I'm thinking is to turn off the *shuffle* and run the `setTimeout` to instruct the player to play a random track handled via Javascript - I need only to play a random track for the first page. Cheers dude!
Shalan