preload mp3 sound
Hi,
Here's my code
var myMonkeySound = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'sounds/mimiplay_monkey.mp3');
// load from file object
var soundMonkey = Titanium.Media.createSound({sound:myMonkeySound,preload:true});
So, the preload part of this doesnt seem to work.
Only when activating the following:
soundMonkey.play();
Do I get this output in the debug/info window
2010-07-27 22:19:27.898 mimiplay v1[37316:5c03] AddRunningClient starting device on non-zero client count
Once the sound has played once, this lag doesnt happen anymore.
2 Answers
-
I was unable to get the preload to work, however for my case, after I had created the sound object, I then called play and then pause functions consecutively. This forces the sound to be loaded, then pauses it, at which point when you come to play the file its preloaded :)
var audioyes = Ti.Media.createSound({ url:'audio/yes.mp3', preload:true }); //fake preload audioyes.play(); audioyes.pause(); //play when needed, works instantly audioyes.play();
You could even set the volume to 0 before you do this, just in case it does attempt to play it briefly, although this hasn't happened to me.
Doesn't work in every case, but solved my problem.
-
Same here..
//LOAD SOUNDS
var audioyes = Ti.Media.createSound({
url:'audio/yes.mp3',
preload:true
});var audiono = Ti.Media.createSound({
url:'audio/boing.mp3',
preload:true
});Doesnt seem to work, am i doing something wrong?