PDA

View Full Version : Preloading Dynamically Loaded MP3


seengee
06-08-2005, 04:13 PM
i'm using a tutorial of Kenny bellews site for "How to Build a Preloader for Dynamically Loaded MP3's"

I have followed his script but it doesnt work the first time that the swf is loaded, the preloader works fine but the mp3 never starts, as soon as i refresh the page and hit play again the mp3 plays fine. So, obviously the MP3 is being preloaded but for some reason never plays..

the script:


mySound = new Sound(this);
//mySound.attachSound("mySound01");
mySoundVolume = 100;
mySound.setVolume(mySoundVolume);


this.onLoad = function() {
mySoundLoading = 0;
_root.loadBar._xscale = mySoundLoading;
};
//END onLoad
this.onEnterFrame = function() {
mySoundBytesTotal = _root.mySound.getBytesTotal();
mySoundBytesLoaded = _root.mySound.getBytesLoaded();
if (preloadNow == 1 && mySoundBytesLoaded>0) {
mySoundLoading = Math.round((mySoundBytesLoaded/mySoundBytesTotal)*100);
_root.percentLoadedText = mySoundLoading+"%";
_root.loadBar._xscale = mySoundLoading;
trace(mySoundLoading);
if (mySoundLoading == 100) {
preloadNow = 0;
_root.mySound.start();
}
}
};




and on a button:


on (press) {
if (playing != true) {
playing = true;
preloadNow = 1;
_root.mySound.loadSound("audio/my_clip.mp3", false);
}
_root.mySound.onSoundComplete = function() {
playing = false;
};
}


Help !!!

Thanks.

Navarone
06-08-2005, 11:50 PM
I think that you need to change the to the following:

on (press) {
if (playing != true) {
playing = true;
preloadNow = 1;
_root.mySound.loadSound("audio/my_clip.mp3", true);//true for streaming; false for event
}
_root.mySound.onSoundComplete = function() {
playing = false;
};
}

oldnewbie
06-09-2005, 03:54 AM
You've used the first part of that tutorial, but should read on the bottom section that starts with...

If you wanted to preload one sound and have it play as soon as it loads, you could also use the onLoad handler. Here is an example using the onLoad handler...

seengee
06-09-2005, 09:12 AM
hi, thanks for the responses.

Navarone, setting the sound to stream kinda removes the point of preloading the sound as it would have streamed by default anyway.

Oldnewbie, I did look at the whole tutorial and tried both methods, each of them suffers similar problems with using event sounds, i dont know if its a cache issue or something but i have had the same problems occassionally with kenny bellews actual fla's which I tested. I've tried playing with relative and absolute paths on the mp3 but that doesnt seem to change anything.