Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Play a .wav file

 
George Lin
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,


When using the following source codes to play a local .wav file, I always find .wav files can not played. Does anyone know what is the trouble?



When using the above program to play a local .wav file, errors such as the following messages are thrown,

Play input audio format=PCM_UNSIGNED, 11025.0 Hz, 8 bit, mono, audio data
Play.playAudioStream does not handle this type of audio on this system.

I have changed many .wav files, but the message "Play.playAudioStream does not handle this type of audio on this system." is always printed and no sound is heard.


Thanks in advance,
George
 
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Applet.newAudioClip(URL of file).play();
 
Keith Biddlecomb
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An alternative way to do it (I do not like using the Applet classes all the time when I'm not dealing with an applet) would be to create an instance of type Clip. Below is an example of how to do this.


I prefer to use this method for playing sounds, because it does not use the Applet class, but I guess in the end it doesnt really matter. Just a note, the line
clip.open(audioInputStream)
doesnt return until the file is read.

Hope that helped.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Keith Biddlecomb:

(snip...)
I prefer to use this method for playing sounds, because it does not use the Applet class, but I guess in the end it doesnt really matter....

Actually it DOES matter. I recall a recent post that was complaining about security-related exceptions. By default an applet won't allow you access to the local file system, so it can be a headache to get things to work the way you want. The code you gave is probably a much better way to avoid the potential headaches caused by an applet's security policy.

Layne
 
George Lin
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Keith,


Your reply is very helpful. I have written a simple sample below which implements your idea. But it still has exceptions when I run this sample. Can you help to find what are the issues?

Originally posted by Keith Biddlecomb:
An alternative way to do it (I do not like using the Applet classes all the time when I'm not dealing with an applet) would be to create an instance of type Clip. Below is an example of how to do this.


I prefer to use this method for playing sounds, because it does not use the Applet class, but I guess in the end it doesnt really matter. Just a note, the line
clip.open(audioInputStream)
doesnt return until the file is read.

Hope that helped.




The thrown exceptions are,




regards,
George
 
George Lin
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Layne,


Originally posted by Layne Lund:

Actually it DOES matter. I recall a recent post that was complaining about security-related exceptions. By default an applet won't allow you access to the local file system, so it can be a headache to get things to work the way you want. The code you gave is probably a much better way to avoid the potential headaches caused by an applet's security policy.

Layne


I think you are correct. I have also written a simple sample in my previous post of this thread which does not use functions from Applet. But it still has exceptions when I run this sample. Can you help to find out what are the issues?


regards,
George
 
George Lin
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kashif,


Originally posted by Kashif Riaz:
Use Applet.newAudioClip(URL of file).play();


I have written the following sample which implements your idea. But it still has some exceptions when I run the following sample.



The exceptions are,



Can you help?


regards,
George
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic