Created
April 16, 2015 13:01
-
-
Save rajubd49/f4c30975eae5036dddac to your computer and use it in GitHub Desktop.
How to play audio randomly - Appcelerator Titanium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Ti.UI.createWindow({ | |
backgroundColor : '#000', | |
layout:'vertical' | |
}); | |
var mp3_array = []; | |
mp3_array.push('music/sound1.mp3'); | |
mp3_array.push('music/sound2.mp3'); | |
mp3_array.push('music/sound3.mp3'); | |
Titanium.Media.audioSessionMode = Titanium.Media.AUDIO_SESSION_MODE_AMBIENT; | |
var current_index = 0; | |
function playSound(index){ | |
var sound = Titanium.Media.createSound(); | |
sound.url = mp3_array[index]; | |
sound.play(); | |
Ti.API.info('Now Playing '+index+': '+mp3_array[index]); | |
sound.addEventListener('complete',function(){ | |
current_index++; | |
if(current_index < mp3_array.length){ | |
playSound(current_index); | |
} | |
else { | |
Ti.API.info('all sounds complete!'); | |
} | |
}); | |
} | |
playSound(current_index); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment