Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

preload mp3 sound


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:


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.

— asked July 27th 2010 by Ali Driver
  • mp3
  • preload
  • sound
1 Comment
  • I have this issue also, its making my sound app almost useless

    — commented August 24th 2010 by Matthew Wise

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
    //play when needed, works instantly

    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.

    — answered November 30th 2010 by Richard Patching
    • Man nice idea… If only setVolume worked for me…

      — commented December 9th 2010 by George Marmaridis
    • This works great, thanks for pointing it out.

      — commented March 7th 2011 by jamie cross
    • You're a genius :D

      I can't believe that 3 years later issues like this are still unresolved! :( If I had known a year and a half ago what I know now I would have used Unity :(

      @George - mysound = Ti.Media.createSound({volume: xxx}); doesn't work at creation but someone pointed out to me that if you create the sound object and then AFTERWARDs do: mysound.volume = 0.05; \\(say) THEN it will work :D (or it does here on Android 2.3.4 & 4.0.1)

      — commented September 15th 2013 by Robin Williams
  • Same here..


    var audioyes = Ti.Media.createSound({

    var audiono = Ti.Media.createSound({

    Doesnt seem to work, am i doing something wrong?

    — answered October 5th 2010 by karl andreasson
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.