Skip to content

Instantly share code, notes, and snippets.

@Seasons7
Created August 21, 2011 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Seasons7/1160447 to your computer and use it in GitHub Desktop.
Save Seasons7/1160447 to your computer and use it in GitHub Desktop.
Titanium Play Sound.
Titanium.UI.setBackgroundColor('#000');
// ウィンドウ作成
var win = Titanium.UI.createWindow({
title:'サウンドテスト',
backgroundColor:'#fff',
barColor:'#3366ff'
});
var button = Ti.UI.createButton({
title:'load',
width:200,
height:40,
bottom:20
});
var soundFile = Ti.Media.createSound({
url:'bell.wav'
});
var soundIsReady = false;
button.enabled = false;
soundFile.volume = 0.0;
soundFile.play();
button.addEventListener( 'click' , function(){
if( soundIsReady == false )
return;
if( soundFile.isPlaying ) {
soundFile.stop();
}
Ti.API.log( 'Sound play' );
soundFile.play();
} );
soundFile.addEventListener( 'complete' , function(){
Ti.API.log( 'complete' );
if( soundIsReady == false ) {
soundIsReady = true;
soundFile.volume = 1.0;
button.enabled = true;
button.title = 'Play';
}
} );
win.add( button );
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment