NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
October 21, 2017, 08:32:51 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
An interaction between two opposites produces a unique outcome. ..."Jules Henri Poincare(1854-1912, One of France's greatest mathematicians)"
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: is it possible to make applet make a sound when i condition is met?  (Read 10190 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
on: December 19, 2008, 02:58:48 pm » posted from:SINGAPORE,SINGAPORE,SINGAPORE

i can't find a button to embed sound clips *.mp3

is it the same as a video file? Cheesy



i found it as a checkbox enabled sound, exploring it now,

hmmmm, doesn't seem to do what i need.

I want the add a line to the event
action

...................*.mp3;

so that everytime the event collosion occurs it will play this *.mp3 file.

how to do it?

I check here and EJS both cannot find the info easily.

thanks!
« Last Edit: December 19, 2008, 03:15:33 pm by lookang » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #1 on: December 21, 2008, 12:43:57 am »

The current version of EJS only support wav file.
You can add other java library which support mp3 if you want to use mp3 in EJS.
For examples: Jlayer-MP3 library at http://www.javazoom.net/javalayer/javalayer.html
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #2 on: December 21, 2008, 11:33:17 am »

i made sound.wav from the mp3 file.

i named sound.wav as a variable

called sound

i try this syntax to make the sound = true ,

but the collision detection syntax i do understand enough.

i tried this on the constraint page but it didnt work
if ( min < TOLERANCE ) { //  1. am i correct to test for the condition min <  TOLERANCE ?, i think min is a variable inside the collision syntax which i can refer to rite?


sound = true; // testing sound on
 
  }
  else {
  sound = false; //testing sound off
  }


Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #3 on: December 21, 2008, 11:52:37 am »

Paco created a SeeSaw.xml to demo how to use wav file in EJS (available for version 3.47).
Please check out the attached image file (illustrate how to set up properties for sound in EJS).

The sound is on/off when value for playSound variable is true/false.


* ejssoundui.png (75.27 KB, 885x311 - viewed 322 times.)
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #4 on: December 21, 2008, 09:56:51 pm » posted from:Singapore,,Singapore

i will analyze this asap.

after looking at the source,
i didn't think putting in the initialization page was "sound = false" but i will try later.

was trying to force the codes to do "sound = false"

will test out again asap
thanks!
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #5 on: December 21, 2008, 10:49:55 pm » posted from:Singapore,,Singapore

i got sound using the action. but i cannot off it.

how to make it play once only?

the codes is this :
ZERO CONDITION:
Code:
for (int i=0; i  x[i] = xTop[i] + l*Math.sin(alpha[i]);
  y[i] = yTop - l*Math.cos(alpha[i]);
 }
 
 // codes for calculation of zero condition based on length
double min = TOLERANCE;
for (int i=0; i  for (int j=i+1; j  double deltax = x[j]-x[i], deltay = y[j]-y[i];
  double allowed = 2*radius;
  double distance = deltax*deltax+deltay*deltay-allowed*allowed;
  if (distance  if (deltax*(omega[j]-omega[i])<0) {
 // take action to take if loop checks for delatx*difference of angular velocities less than zero
  ball1 = i; ball2 = j; min = distance;
//  sound = true; // testing sound on
 
//  }
//  else { sound = false; //testing sound off
  }
 
 
  }
  }
}
return min;

and i added the acion
ACTION
Code:
double aux = omega[ball1]; // assign aux to omega[ball1]
omega[ball1] = omega[ball2]; // assign omega[ball1] = omega[ball2], because mass same so this will work
omega[ball2] = aux;
sound = true; // sound produced added by weelk but it is non stop why?
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #6 on: December 21, 2008, 11:14:32 pm » posted from:Singapore,,Singapore

i think the approach is wrong here.

as the codes are constantly testing ball1 size against ball2 size so even when there is no collision, the condition is constantly achieved.

i think i added the sound there so it will not give me the result of a sound when a collision occur but also during balls rubbing each other at the bottom.


should i use another approach like test of momentum transfer?



or maybe  ball1 size against ball2 size && v1 or v2 > 0 ?

it is harder than i thought.
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #7 on: December 21, 2008, 11:49:02 pm »

If you set the sound to true, it will play the sound continuously.
You need to set the sound to off if you do not want to play it.
There are many way to do it.
For example: if you want the sound to play for 0.5 second.
Define a varrable t_on to remember when the time is on.
add t_on=t; just after you set sound=true;
And add the following code to constraint page:
If (Math.abs(t-t_on)>0.5)sound=false; // turn the sound off when it has been play for 0.5s.

You need to tell the program/computer what you want to do.
The program/computer can not decide it for you!
Logged
lookang
Hero Member
*****
Offline Offline

Posts: 1784


http://weelookang.blogspot.com


WWW
«
Embed this message
Reply #8 on: December 22, 2008, 12:10:01 pm »

excellent advise!

variable added:
sound // boolean  true for play false for no play
t_on // time of sound to be play

Constraints:
if (Math.abs(t-t_on)>0.04) sound=false; // turn the sound off when it has been play for 0.04s

Evolution
Event
Action page added
sound = true; // sound produced
t_on = t;

work like a charm Smiley
i will post my derived newton cradle from prof paco in the community board as a download-able jar file
http://www.phy.ntnu.edu.tw/ntnujava/index.php?action=dlattach;topic=824.0;attach=499

you are the best, prof hwang
« Last Edit: December 22, 2008, 12:17:21 pm by lookang » Logged
Pages: [1]   Go Up
  Print  
An interaction between two opposites produces a unique outcome. ..."Jules Henri Poincare(1854-1912, One of France's greatest mathematicians)"
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
how to make the symbol "alpha" appear as α in the java applet
Questions related to EJS
lookang 2 12905 Last post August 13, 2007, 07:48:56 am
by lookang
How to make sure the exported web based applet pages load quickly and work?
Questions related to EJS
lookang 1 5231 Last post January 16, 2009, 08:00:36 pm
by lookang
how to make magnet1 and magnet2 in a single applet with different rotation?
Questions related to EJS
lookang 1 4087 Last post May 01, 2010, 01:50:08 pm
by lookang
how do make Ejs applet run forever unless the pause or reset
Questions related to EJS
lookang 3 4857 Last post June 21, 2010, 07:52:30 pm
by Fu-Kwun Hwang
How make applet run one time only/board:23-100-
Question related to Physics or physics related simulation
ahmedibrahim 4 4370 Last post July 17, 2010, 12:35:45 am
by ahmedelshfie
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.061 seconds with 23 queries.since 2011/06/15