Why do the sounds play twice?

This was working properly in 1.7.5 but now plays twice in a row.

I have dynamically generated imageviews with a click event that calls a function that creates a sound that plays the sound and releases on complete.

Code as follows:

function pickSound() {
    var toss = Math.ceil(Math.random() * 12);
    if(toss < 10) {
        toss = "0" + toss;
    var sound= Titanium.Media.createSound({
        url : 'sound/sound' + toss + '.ogg'
    sound.looping = false;
    var played= zombieDies.addEventListener('complete', function(e) {
        sound.removeEventListener('complete', played)


It is the only effect that is played twice and it is not consistently played twice.

— asked 4 years ago by Dooley P
  • As an added bonus, some of these sounds do not play at all.

    — commented 4 years ago by Dooley P
  • I suppose clarification would help.

    There are twelve ogg files. Of them, some play twice, some don't play at all, and some play normally.

    Is there a new criteria I should be aware of when exporting/handling ogg files?

    — commented 4 years ago by Dooley P
  • I converted all the sounds to mp3 and now some of them play… some of them do not.

    All other sounds in the game are functioning normally.

    — commented 4 years ago by Dooley P

2 Answers

  • It's not a solution or answer, but to work around the issue I decided to try using an audioplayer instead of a sound.
    It works very well, with the mp3s (haven't tested with oggs) and remains dynamic.

    There doesn't seem to be any way of cleaning up after (i'm thinking of release) so i'm assuming once the function runs out, the audioplayer will be cleaned out or forgotten?
    Hence memory isn't an issue?

    I hope this helps someone.

  • Okay, the audioplayer actually doesn't work consistently as I intially expected.
    So I've redacted all that nice elegant code, and put in a 12 case switch.

    — answered 4 years ago by Dooley P
    • Oh and the ogg's are still firing twice.

      — commented 4 years ago by Dooley P
    • But the mp3s are not.
      However, if I don't have a reset before playing the sound, I get force close.

      — commented 4 years ago by Dooley P
    • I've returned to the ogg format again, as the mp3 format seems heavy and given I have twelve different sounds, the switch plus the mp3 is actually too slow.
      Also, using the mp3s, the game freezes after five minutes, where while using oggs, I can continue to play much much longer.

      This is getting really weird.

      — commented 4 years ago by Dooley P