Audio Problem (OnCreate)
Monkey Targets Forums/Android/Audio Problem (OnCreate)
| ||
Hi, I'm having problems with PlaySound, I have put the function within the OnCreate method to loop, but sadly it doesn't play, anyone else having problems? |
| ||
What format is your sound in? Check the Audiotest sample: #if TARGET="flash" shoot=LoadSound( "shoot.mp3" ) tinkle=LoadSound( "tinkle.mp3" ) #else If TARGET="android" shoot=LoadSound( "shoot.ogg" ) tinkle=LoadSound( "tinkle.ogg" ) #else shoot=LoadSound( "shoot.wav" ) tinkle=LoadSound( "tinkle.wav" ) #endif Notice the pre-complier for Android. |
| ||
The format is ogg, although the app works fine in HTML5, but sadly the sound doesnt play on Android. Audiotest sample, works fine on Android. very strange! |
| ||
Im able to play only short ogg files on android. Longer samples just mute. |
| ||
I have problems with audio playing on the OnCreate event also, but in the Iphone! I have added a timer, and played the audio when the timer=1 and it worked! So it's a problem on the Android/IphonePort. Html5 works fine! |
| ||
Hi, I can reproduce this on android but not iOS. The problem seems to be that android loads sounds asynchronously (on another thread - completely undocced?), and if a sound hasn't fully loaded it will fail to play. Therefore LoadSound followed by PlaySound isn't giving the sound a chance to load. I've been able to wangle a solution with a nasty 'play/sleep/repeat' loop if play fails, but it ain't pretty and I think in general it's best to treat sounds a bit like images - you can only safely play them in the next OnUpdate or OnRender. Mojo only calls OnUpdate and OnRender when everything is fully loaded, so doing it this way means you don't have to worry about whether a sound has finished loading yet, regardless of target platform. I also plan to add an IsLoading method to Image/Sound, which will always return true in OnUpdate/OnRender, but will return false in OnLoading if the resource hasn't loaded yet. |
| ||
Glad someone else it tackling all these Android quirks! ... ;) |
| ||
Hi, so is the solution to this to basically make sure there is quite a delay between loading a sound and playing it? Edit : Actually I am really struggling to play long sound files even with a 60 frame delay between loading and playing. This even happens in an Android app that does absolutely nothing else. |
| ||
I think the solution was to create a bool field for the the sound you want to play. Set it to false in OnCreate() and then in OnUpdate() play the sound if it's false, and then set it to true. Because OnUpdate() only gets called after loading is complete. |
| ||
Thanks Soap, yeah that is basically what I am doing (but with a counter that kicks in at 0 and starts at 60 |