createSound, on complete jump to next sound
I'm creating a music player. But since all the audio files are running within the application I can't use the createAudioPlayer function.
So what i've done is create a variable which holds the player.. BUT when the sound is finished i need to assign a new song.. Thus create a new Sound instance.. so, normally, in javascript when you overwrite the player var it should be empty.. but, it seems like Titanium just creates a new instance with the same name (?).
Code:
var _num = 1;
var _max = 3;
var player = null;
function playSound(num) {
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'sound/' + num + '.mp3');
_num = num;
player = Ti.Media.createSound({
url: file.nativePath,
preload: true
});
player.addEventListener('complete', function() {
if(_num < _max) {
_num++;
} else {
_num = 1;
});
playSound(_num);
}
I do it like this, since player.setUrl() or player.setFile() don't exists and i can't figure out another way to use it..
1 Answer
-
Please post an answer with the way you used to do it so that we see the solution.
Thanks