sound release kills eventListener

You must Login before you can answer or comment on any questions.

Hi, i have a program that will play 12 different local sound files trough the program. The ending of each sound will trigger a following function. To do this I use Titanium.Media.createSound(); since it's local files. I have a eventListener for complete aadded to sound object. Then I just update the url for sound object for playing next sound. The problem is that for the sound object to really update to the new sondfile I had to add a release function wich led to complete lister to stop work and I get stucked at the second sound. Does this make any sense and do someone know what to do?

Some code(I cut out the parts thats involving sound):

var sound = Titanium.Media.createSound();
sound.addEventListener('complete',soundcomplete);
 
function soundcomplete(){
    sound.release();
    afterSound();
}
 
function afterSound(){
    // lots of functionality that dosn't have anything to do with the sound
}
 
// -- this is the function that will call a new sound
function foundObject(){
    if(oldType=="Fraga"){
        sound.url=arrFragor[nextCount].snd;
        sound.play();       
    }
    else{
        afterSound();
    }
}
So.. afterSound just get called after the first time, if I remove sound.release(); and add a stop the complete listener will work but it dosn't play a new sound instead it just keeps playing the first sound file everytime. Hope someone know anything about this

Best regards! /magnus

2 Answers

Accepted Answer

hi Magnus,

when you use release() of sound it releases object also so you can do like this

var sound = Titanium.Media.createSound();
sound.addEventListener('complete',soundcomplete);
 
function soundcomplete(){
    sound.release();
    var sound = Titanium.Media.createSound();
    sound.addEventListener('complete',soundcomplete);
    afterSound();
}

Thanks alot Mitul, it worked perfect with a small modification, instead of creating a new var inside the complete function I addad a new createSound to the old "sound" var, so it still keeps accessible outside this function.

function soundcomplete(){
    sound.release();
    sound = Titanium.Media.createSound();
    sound.addEventListener('complete',soundcomplete);
    afterSound();
}
thanks again!

Your Answer

Think you can help? Login to answer this question!