Hello, i have found this question in Q&A, but this isn't go to next song? i have tried everything, but can't make it:(
var win = Ti.UI.currentWindow; var mp3_array = []; mp3_array.push('1.mp3'); mp3_array.push('2.mp3'); mp3_array.push('3.mp3'); mp3_array.push('4.mp3'); mp3_array.push('5.mp3'); Titanium.Media.audioSessionMode = Titanium.Media.AUDIO_SESSION_MODE_AMBIENT; var sound = Titanium.Media.createSound(); var current_index = 0; function playSound(index){ sound.url = mp3_array[index]; sound.play(); } sound.addEventListener('complete',function(){ // increment the array index Ti.API.info("Song Finished,Go To Next Song"); Ti.API.info(current_index); current_index++; if(current_index < mp3_array.length){ // play the next mp3 in the array playSound(current_index); } else { Ti.API.info('all sounds complete!'); } }); // play the first mp3 in the array @ index 0 playSound(current_index); win.open();
3 Answers
Accepted Answer
Try this:
var songs = [] // push your sounds into the array var index = 0; loopMessageSound(); function loopMessageSound() { messageSound = Ti.Media.createSound(); messageSound.url = songs[index].sound; messageSound.addEventListener('complete', function(e) { index ++; if (index < songs.length) loopMessageSound(); }); messageSound.play(); }
Thank you very much :)), exactly it works like this
var win = Ti.UI.currentWindow; var songs = [] songs.push('1.mp3'); songs.push('2.mp3'); songs.push('3.mp3'); // push your sounds into the array Ti.API.info(songs.length); var index = 0; loopMessageSound(); function loopMessageSound() { messageSound = Ti.Media.createSound(); // i have deleted the .sound , is this important??? messageSound.url = songs[index]; Ti.API.info(messageSound.url); messageSound.addEventListener('complete', function(e) { index ++; if (index < songs.length) loopMessageSound(); }); messageSound.play(); } win.open();how can i turn to the first song when the songs finished?
you can get more help on this topic from here.
Your Answer
Think you can help? Login to answer this question!