File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Play a .wav file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Play a .wav file" Watch "Play a .wav file" New topic
Author

Play a .wav file

George Lin
Ranch Hand

Joined: Jan 11, 2005
Posts: 125
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

Joined: Jan 08, 2005
Posts: 375
Use Applet.newAudioClip(URL of file).play();
Keith Biddlecomb
Greenhorn

Joined: Jan 25, 2005
Posts: 5
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.


Keith Biddlecomb<br />Computer Science<br />University of Virginia
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
George Lin
Ranch Hand

Joined: Jan 11, 2005
Posts: 125
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

Joined: Jan 11, 2005
Posts: 125
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

Joined: Jan 11, 2005
Posts: 125
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Play a .wav file