Created
August 21, 2011 10:33
-
-
Save Seasons7/1160447 to your computer and use it in GitHub Desktop.
Titanium Play Sound.
This file contains 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
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