MP3 Preload Woes
- Started
- Last post
- 4 Responses
- autonoma
I'm using the following code to preload music for an MP3 player I'm making:
Sound.prototype.checkLoadProgres... = function () {
var kbLoaded = Math.floor(this.getBytesLoaded...
var kbTotal = Math.floor(this.getBytesTotal...
var percentDone = isNaN(Math.floor(kbLoaded/kbTota... * 100)) ?
0 : Math.floor(kbLoaded/kbTotal * 100);
this.onBytesLoaded(this.getBytes...
this.getBytesTotal(),
kbLoaded,
kbTotal,
percentDone);
}Sound.prototype.clearLoadCheck = function () {
if (this.loaderID) {
clearInterval(this.loaderID);
}
}Sound.prototype.preloadSound = function (url, isStreaming) {
this.clearLoadCheck();
this.loaderID = setInterval(this, "checkLoadProgress", 200);
this.loadSound(url, isStreaming);
}music = new Sound();
music.onLoad = function (success) {
this.clearLoadCheck();
if (success) {
this.start();
mainTimeline.loadMsg = "Finished";
} else {
mainTimeline.loadMsg = "Failed";
}
}music.onBytesLoaded = function (bytesLoaded, bytesTotal, kbLoaded, kbTotal, percentLoaded) {
mainTimeline.loadMsg = percentLoaded + "%";
}This is working great so far, but I have one question:
The player features many different song clips. If it's in the process of preloading a file, and you make another selection, it performs the failure operations in the music.onLoad function. How would I go about stopping the preload and starting it over with a newly selected clip? Also, how can I just stop the preload?
Thanks for your help in advance.
- JazX0
too much crap to read sorry can't help, download one that already has been done where you JUST need to put in the mp3
- autonoma0
I really prefer starting from scratch over molding another's design into one I like. Besides, doing that wouldn't really give me a good idea of how things work.
Thanks anyway.
- lifeinsodium0
where can one get one of these premade preloaders?
- autonoma0
This might help in viewing the code the right way: