Click to See Complete Forum and Search --> : SwfObject loading new mp3 help


mwpwalshe
08-10-2007, 07:49 AM
I am having trouble writing a function to load and play a new mp3 file, ..Any code or links to code would be appreciated - wasted too much time on this already
Thanks
Here is what I have:
function updateSong() {
var fo = new SWFObject("flash/previewplayer.swf", "mp3player", "300", "350", "8.0.15", "#ffffff", true);
// need this next line for local testing, it's optional if your swf is on the same domain as your html page
fo.addParam("allowScriptAccess", "always");
fo.addVariable("file","flash/test.mp3");
fo.write("flashcontent");
}
I have this function and it working to update, but it creates a new object everytime which is not what I want, I can get my original object via:
var flashMp3Player;
function init() {
if (document.getElementById) {
flashMp3Player = document.getElementById("mp3player");
}
}
surly I can just update this object:
flashMp3Player. "load new song" ????????

Any Ideas

Gord
08-10-2007, 03:22 PM
Hi.

I think your problem is that the swf file needs to contain script which will go and get a different mp3 file.
You cannot do it with Javascript alone.

Think of a swf object as not so much a media player , more of a programmable object. If your playerpreview.swf does not contain the actionScript code to be able get a different mp3 file, then it won't be able to do it.

The code you are using, as you have correctly identified, loads a new swf. object.

I believe your options are.

1/Find out whether playerpreview.swf was written with the intention of being able to fetch alternative mp3 files.If so, you will need to know the actionScript function name & what data it expects to recieve.
2/Create a flash .swf file that does what you want.
3/Search the web for a freebie .swf that was made to do what you want.( swap mp3 files).
note: if you can find a .swf object file which uses a seperate imported actionScript file then it is reletively easy for an actionScript programmer to manipulate this for you.
I know that there are similar freebies for .swf video out there so you may be lucky.

Hope this helps

Gord