FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How to play sound in templateRender

2 posters

Go down

How to play sound in templateRender Empty How to play sound in templateRender

Post  chondrite Mon Jun 15, 2009 3:33 pm

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!

chondrite

Posts : 24
Join date : 2009-06-15

Back to top Go down

How to play sound in templateRender Empty Re: How to play sound in templateRender

Post  yarri Mon Jun 15, 2009 4:05 pm

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

yarri

Posts : 81
Join date : 2009-04-10

Back to top Go down

How to play sound in templateRender Empty Re: How to play sound in templateRender

Post  chondrite Mon Jun 15, 2009 4:27 pm

Yarri,

That worked. Thank you very much!

chondrite

Posts : 24
Join date : 2009-06-15

Back to top Go down

How to play sound in templateRender Empty Re: How to play sound in templateRender

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum