Javascript - find swfobject on included page and call javascript function

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-04-27T19:59:18Z Indexed on 2010/04/28 0:13 UTC
Read the original article Hit count: 745

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about swfobject