views:

446

answers:

4

I’m using the following script on my website to play an mp3 in flash. To instantiate the flash object I use the swfobject framework in a javascript function. When the function is called the player is created and added to the page.

The rest of the website is in php and the page calling this script is being included with the php include function. All the other used scripts are in the php 'master'-page

var playerMp3 = new SWFObject("scripts/player.swf","myplayer1","0","0","0");
    playerMp3.addVariable("file","track.mp3");
    playerMp3.addVariable("icons","false");
    playerMp3.write("player1");

    var player1 = document.getElementById("myplayer1");
    var status1 = $("#status1");

    $("#play1").click(function(){
        player1.sendEvent("play","true");
        $("#status1").fadeIn(400);
        player4.sendEvent("stop","false");
        $("#status4").fadeOut(400);
        player3.sendEvent("stop","false");
        $("#status3").fadeOut(400);
        player2.sendEvent("stop","false");
        $("#status2").fadeOut(400);
    });
    $("#stop1").click(function(){
        player1.sendEvent("stop","false");
        $("#status1").fadeOut(400);
    });
    $(".closeOver").click(function(){
        player1.sendEvent("stop","false");
        $("#status1").fadeOut(400);
    });
    $(".accordionButton2").click(function(){
        player1.sendEvent("stop","false");
        $("#status1").fadeOut(400);
    });
    $(".accordionButton3").click(function(){
        player1.sendEvent("stop","false");
        $("#status1").fadeOut(400);
    });
    $(".turnOffMusic").click(function(){
        player1.sendEvent("stop","false");
        $("#status1").fadeOut(400);
    });
});

I have a play-button with the id ‘#play1’ and a stop-button with the id ‘#stop1’ on my page. A div on the same page has the id ‘#status1’ and a little image of a speaker is in the div. When you push the playbutton, the div with the speaker is fading in and when you push the stopbutton, the div with the speaker is fading out, very simple. And it works as I want it to do.

But the problem is, when a song is finished, the speaker doesn’t fade out. Is there a simple solution for this? I already tried using the swfobject framework to get the flash player from the page and call the ‘IsPlaying’ on it, but I’m getting the error that ‘swfobject’ can’t be found. All I need is a little push in the right direction or an example showing me how I can correctly get the currently playing audio player (in flash), check if it’s playing and if finished, call a javascript function to led the speaker-image fade-out again. Hope someone here can help me

+2  A: 

Rob,

kun je vanuit je flash niet je javscript aanroepen dmv een regel als deze: getURL("javascript:StatusFadeOut();");

in die functie stop je dan de volgende regel: $("#status1").fadeOut(400);

Niek
Hey Niek, Thnx voor je reactie! Maar helaas kan dat niet. We hebben geen toegang tot de fla. Hebben alleen maar een SWF file. Toch bedankt, als je andere suggestie hebt hoor ik het graag!:D
Rob
+1  A: 

The 'swfobject not found' error is often due to mixing up SWFObject 1.5 and 2.x syntax (2.x is a complete rewrite and not backwards-compatible). See http://learnswfobject.com/advanced-topics/detecting-swfobject-version/

The code you posted uses SWFObject 1.5 syntax, which means all references to the SWF should be accessed via your player1 variable, as you've written.

RE: the fading, is the speaker icon part of your SWF? You can't 'fade out' a SWF using CSS/JavaScript. In this case you'd have two options:

  1. Fade IN a HTML-based mask OVER the SWF which gives the appearance of fading out the SWF. This can be achieved with a DIV styled to look like your background. Here's a tutorial for placing HTML elements over SWFs.

  2. Alter your SWF to fade out the speaker icon using an internal ActionScript function, and invoke the function using ExternalInterface.

pipwerks
No the speaker icon is just a simple image inside a div.I'll try your suggestions and let you know.
Rob
A: 

No, the image is not a part of the swf and i don't have the .fla file, so i cannot put any code in flash.

My question is; is there a piece of javascript that says to the .swf file: fade the speaker image (which is in a div on the page) out when a song is finished.

Btw, Rob is my brother and he's helping with this problem.

Koen
Koen try this;var player1 = document.getElementById("myplayer1");alert(player1.IsPlaying());and let us know here what happens. As pipwerks said, we use the 1.5 syntax so we should be able to acces the player through that variable.
Rob
A: 

Because lack of time we've decided to run a JS timer in the background with a length equal to the length of the mp3 playing in flash. In time i'll rewrite the code to the swfobject 2.x syntax. Any suggestions to this problem are still welcome!

Rob