Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Playing .Wav sounds?
 Post subject: Playing .Wav sounds? Post rating: 0   New post Posted: Wed 25 Aug, 2010, 02:13 

User rating: 0
Joined: Mon 09 Aug, 2010, 21:49
Posts: 30
Can anyone reccomend a good class to play a .wav sound file? Is there maybe something for this already built into JForex?


 
 Post subject: Re: Playing .Wav sounds? Post rating: 0   New post Posted: Wed 25 Aug, 2010, 08:14 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please consider this https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=7&t=563&hilit=Alerter


 
 Post subject: Re: Playing .Wav sounds? Post rating: 0   New post Posted: Wed 25 Aug, 2010, 17:24 

User rating: 0
Joined: Mon 09 Aug, 2010, 21:49
Posts: 30
Thank you for that reply. The code you linked to is very helpful for a number of things. However, if all someone wants to do is play a sound, there is a lot of extra info there.

For future reference if someone comes across this thread, I believe all the code that is needed just to play a sound is below. I am no java expert though and would appreciate if someone can confirm.

   
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import java.io.File;


private void playSound(File wavFile) throws JFException
{
   try
   {
      AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(wavFile);
      AudioFormat af = audioInputStream.getFormat();
      int nSize = (int) (af.getFrameSize() * audioInputStream.getFrameLength());
      byte[] audio = new byte[nSize];
      DataLine.Info info = new DataLine.Info(Clip.class, af, nSize);
      audioInputStream.read(audio, 0, nSize);
      Clip clip = (Clip) AudioSystem.getLine(info);
      clip.open(af, audio, 0, nSize);
      clip.start();
   }
   catch (Exception e)
   {
      e.printStackTrace();
      throw new JFException(e);
   }
}



I am getting a warning on this line:
e.printStackTrace();

it's not coming up as an error, but only a warning. Not sure if its a big deal. The warning text says "Throwable.printStackTrace() should be removed"


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com