Question

I currently have a function setup to play a sounds in TideSDk (an application wrapping program), is as follows: (note: the Ti.Media is an API from TideSDk)

function playSound(soundFilePath){
        var s = Ti.Media.createSound(soundFilePath);
        s.play();
        }

I then call this function like so: (again don't worry about the Ti.Filesystem, more API)

$("#audioMain").click(function() {
         var sound = 'Level1/my_body_here_i_am/audio/f_sentence1.mp3';
         playSound(Ti.Filesystem.getFile(Ti.Filesystem.getResourcesDirectory(), sound).nativePath())            
            });

My problem here is I need to somehow bind the 'ended' event to the sound that plays, it would usually be as easy as:

$('#someID').bind('ended', function() {
    //do something
    });

But as I can't work with IDs or Classes here I don't know what to bind to. I've tried:

sound.addEventListener("ended", function() { }); or
s.addEventListener("ended", function() { });

But can't seem to get any of this to work, I'm not sure if I have to include this bind event in the original function.. it's been furstrating me for hours now.

Thanks community.

Was it helpful?

Solution

After having a quick browse of the TideSDK docs it seems as though you can do something like this:

function playSound(soundFilePath){
        var s = Ti.Media.createSound(soundFilePath);
        s.play();
        s.onComplete(function(){
           alert("sound finished");
        });
}

Have a look here for all the specifics - http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.Media.Sound

Looks like calling Ti.Media.createSound(); returns the Ti.Media.Sound object which has the methods .play() and the others listed in the link i've provided. Hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top