Hi,
It seems that I can choose among these alternatives:
Play different sounds, but lose playback at some point with no errors raised
OR
Play the same sound over and over - because you can change the URL on the sound object, but you can't change what file it plays! (this is probably why it doesn't run out of resources)
The following program demonstrates that:
var win = Ti.UI.createWindow({ navBarHidden : true, exitOnClose : true, backgroundColor : 'white', }) // Replace these with any sounds you have lying around // Do NOT use mp3s - Ti fails miserably with mp3s on Android var soundUrl = ['/51.ogg', '/50.ogg'] var counter1 = 0 var btn1 = Ti.UI.createLabel({ text : 'new soundobject 0', backgroundColor : 'yellow', color : 'black', height : 50, top : 50, }) // This way we can play different sounds // But we'll run out of resources, and the sounds // will stop playing. With the sounds i use, and my phone, this happens after 30-35 times // Ti KNOWS that something went wrong // (the debug-log says so) but it does not raise an error btn1.addEventListener('click', function(e) { var sound = Ti.Media.createSound({ url : soundUrl[counter1 % 2] }) sound.play() // This error is almost never triggered // Would have been nice if it triggered when the sound fails to play! sound.addEventListener('error', function() { alert(counter1) }) btn1.text = 'new soundobject ' + ++counter1 + '\n' + sound.url }) var counter2 = 0 var btn2 = Ti.UI.createLabel({ text : 'same soundobject 0', backgroundColor : 'yellow', color : 'black', height : 50, top : 150, }) var sound2 = Ti.Media.createSound({}) // This way we can keep on without running out of resources // BUT we can't change the sound. We can change the URL property // of the sound object, but the first URL we gave it, remains in effect. btn2.addEventListener('click', function(e) { sound2.stop() // this does not work sound2.url = soundUrl[counter2 % 2] // Ti.Media.Sound does not have a setUrl method // the docs says it has // sound2.setUrl(soundUrl[counter2 % 2]) sound2.play() sound2.addEventListener('error', function() { alert(counter2) }) btn2.text = 'same soundobject ' + ++counter2 + '\n' + sound2.url }) win.add(btn1) win.add(btn2) win.open()This is all on android of course.
Summary:
No errors raised when errors happen
Sound-object does not have a setUrl method, which contradicts the documentation ( http://docs.appcelerator.com/titanium/2.1/index.html#!/api/Titanium.Media.Sound )
Impossible to assign new Url to soundobject using soundobject.url = 'xxx.ogg'
mp3 files causes even more errors and might terminate your program abruptly
Is this state of affairs likely to change any time soon?
1 Answer
I was facing problem in videos,replace the code for the audio accordingly for your case
var btn = Ti.UI.createButton(); win.add(btn); btn.addEventListener('click',function(){ var Movie = Titanium.Media.createVideoPlayer({ url:'titanium'+abc+'.mp4', backgroundColor:'#111', movieControlMode:Titanium.Media.VIDEO_SCALING_ASPECT_FIT, }); Movie.addEventListener('complete',function(e){ abc++; if(abc!=6) btn.fireEvent('click'); else abc = 1; Movie.hide(); }); Movie.play(); });
Your Answer
Think you can help? Login to answer this question!