Skip to content

Instantly share code, notes, and snippets.

@dmnkhhn
Created August 18, 2010 18:24
Show Gist options
  • Save dmnkhhn/535709 to your computer and use it in GitHub Desktop.
Save dmnkhhn/535709 to your computer and use it in GitHub Desktop.
// this little snippet demonstrates how you can handle multiple sounds with just one play button
// switch through the sounds with a simple scroll gesture (by using a ScrollableView
// this code is not complete!! Use it on your own risk. :-)
function createSound(url) {
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, url);
return Titanium.Media.createSound({sound:file});
};
// called once, loading the first sound to play
var sound = createSound('myfile.mp3');
// var scrollView = Titanium.UI.createScrollableView({});
scrollView.addEventListener('scroll', function(e) {
var page = e.currentPage;
sound = createSound(soundfiles[page][0].file);
});
// var play = Titanium.UI.createButton({})....
play.addEventListener('click', function()
{
sound.play();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment