You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

olihar

Trainee

  • "olihar" started this thread

Posts: 139

Location: Iceland

Occupation: Interaction Designer

  • Send private message

1

Wednesday, June 10th 2009, 3:36pm

play sound on keypress - problem

Hi gang and Klaus

I have a little problem I don't seem to get buy... I am creating an installation where I will be hacking a keyboard to be able to make step-able keys.

What I am trying to do is if Key is down it plays a certain sound and it keeps playing it until the key has been released. How I am doing this right now is like this.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<plugin name="soundinterface" url="plugins/soundinterface.swf" rootpath="%CURRENTXML%" onloaded="" />


	<events
			onkeydown="action(keydown);"
			onkeyup="action(keyup);"
			/>

	<action name="keydown">
		trace(keydown - keycode=,keycode);
		if(keycode == 83, playsound(s1,breathe.mp3); );
	</action>
	
		<action name="keyup">
		trace(keyup - keycode=,keycode);
		if(keycode == 83, stopsound(s1); );

	</action>


But the problem there is, as soon as key 83 is pressed and being held down the sound just starts playing over and over again from the beginning only getting small portion of the sound... Is it possible to have an action that would be "keyPressed" that states if the key is being held down keep on running the sound?

I hope you get what I am getting at.

Hope for a quick reply... Thanks gang.

olihar

Trainee

  • "olihar" started this thread

Posts: 139

Location: Iceland

Occupation: Interaction Designer

  • Send private message

2

Friday, June 12th 2009, 1:26pm

No one familiar with any solution to this problem...?

3

Monday, June 15th 2009, 4:42pm

Hi,

thanks for this note, yes I will try to add something like also a "keypressed" event,

for the moment - you could add a own custom variable to check it that key was already pressed:
- set a variable to true when the key was pressed,
- set it to false when released,
- and check for this variable on keypress

e.g.

Source code

1
2
3
4
5
6
7
8
9
<action name="keydown">
trace(keydown - keycode=,keycode);
if(keycode == 83, if(key83_pressed != true, trace(play sound);set(key83_pressed,true););  );
</action>

<action name="keyup">
trace(keyup - keycode=,keycode);
if(keycode == 83, trace(stop sound);set(key83_pressed,false); );
</action>


best regards,
Klaus

olihar

Trainee

  • "olihar" started this thread

Posts: 139

Location: Iceland

Occupation: Interaction Designer

  • Send private message

4

Monday, June 15th 2009, 5:22pm

Thanks for reply Klaus, I tried to do this very quickly but did not get it to work, did you try it?

I will have to look a bit better into it a little later today.

olihar

Trainee

  • "olihar" started this thread

Posts: 139

Location: Iceland

Occupation: Interaction Designer

  • Send private message

5

Monday, June 15th 2009, 10:32pm

I have it like this now and there is no sound.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<plugin name="soundinterface" url="plugins/soundinterface.swf" rootpath="%CURRENTXML%" onloaded="" />


	<events
			onkeydown="action(keydown);"
			onkeyup="action(keyup);"
			/>

<action name="keydown">
trace(keydown - keycode=,keycode);
if(keycode == 83, if(key83_pressed != true, playsound(s1,breathe.mp3); set(key83_pressed,true););  );
</action>

<action name="keyup">
trace(keyup - keycode=,keycode);
if(keycode == 83, stopsound(s1); set(key83_pressed,false); );
</action>


What am I doing wrong?

6

Monday, June 15th 2009, 11:22pm

Hi,

the code looks okay,

try using the latest krpano version,
in beta 7 for example it will not work correctly,

best regards,
Klaus

olihar

Trainee

  • "olihar" started this thread

Posts: 139

Location: Iceland

Occupation: Interaction Designer

  • Send private message

7

Monday, June 15th 2009, 11:38pm

Yes I am using the Beta 8 and this code does not work.

EDIT: I had by some way put the old Beta 7 over the swf file now with Beta 8 it seems to work like a charm.... Nice...

Thanks again Klaus

olihar

Trainee

  • "olihar" started this thread

Posts: 139

Location: Iceland

Occupation: Interaction Designer

  • Send private message

8

Monday, June 15th 2009, 11:45pm

While i have you on the topic, would it be hard to implement a fade on the keyup.. so the sound fades smoothly?

EDIT: just to make sure I am clear fade the volume down, could happen pretty fast, its just to try and get rid of "clicks" when sounds are cut all of a sudden.

Just some brainstorms for my own project and some future ideas for you.

This post has been edited 1 times, last edit by "olihar" (Jun 16th 2009, 12:01am)


9

Friday, June 19th 2009, 11:41pm

Hi,

"fade" functions are already in work for the soundinterface plugin

best regards,
Klaus

Similar threads