How to play sound in templateRender
2 posters
How to play sound in templateRender
Hello,
I want a sound to play when I touch a certain region of the screen. I have the code checking to see if the user is over the region, like this:
////////////////////////////////////////
In templateRender:
if(userIsTouchingRegion()){
sio2SoundPlay(my_sound);
}
////////////////////////////////////////
The problem is: because it is being called every frame, the sound restarts over and over and never even finishes.
So, my question is: how do I check if the sound is already playing, and if it ISN'T, play the whole thing, without looping?
By using this:
////////////////////////////////////////
if(my_sound->state != SIO2_SOUND_PLAY){
sio2SoundPlay(my_sound);
}
////////////////////////////////////////
This prevents it from restarting, but it only plays once.
I need it to play whenever the user is touching, EXCEPT when it's already playing.
I hope I've explained this clearly. Thank you in advance!
I want a sound to play when I touch a certain region of the screen. I have the code checking to see if the user is over the region, like this:
////////////////////////////////////////
In templateRender:
if(userIsTouchingRegion()){
sio2SoundPlay(my_sound);
}
////////////////////////////////////////
The problem is: because it is being called every frame, the sound restarts over and over and never even finishes.
So, my question is: how do I check if the sound is already playing, and if it ISN'T, play the whole thing, without looping?
By using this:
////////////////////////////////////////
if(my_sound->state != SIO2_SOUND_PLAY){
sio2SoundPlay(my_sound);
}
////////////////////////////////////////
This prevents it from restarting, but it only plays once.
I need it to play whenever the user is touching, EXCEPT when it's already playing.
I hope I've explained this clearly. Thank you in advance!
chondrite- Posts : 24
Join date : 2009-06-15
Re: How to play sound in templateRender
This is more of an OpenAL question. Check out the code in sio2SoundUpdateState(), you should be able to check the state with call to alGetSourcei() and respond to a state of:
AL_PLAYING
--yarri
PS: http://connect.creativelabs.com/openal/Documentation/OpenAL_Programmers_Guide.pdf
AL_PLAYING
--yarri
PS: http://connect.creativelabs.com/openal/Documentation/OpenAL_Programmers_Guide.pdf
yarri- Posts : 81
Join date : 2009-04-10
Re: How to play sound in templateRender
Yarri,
That worked. Thank you very much!
That worked. Thank you very much!
chondrite- Posts : 24
Join date : 2009-06-15
Similar topics
» Trying to play a sound
» Sound Example
» Stream sound
» Hook a sound to a physics collision
» Duplicating an object with sound attached
» Sound Example
» Stream sound
» Hook a sound to a physics collision
» Duplicating an object with sound attached
Permissions in this forum:
You cannot reply to topics in this forum