This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Play a .wav file  RSS feed

 
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
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Applet.newAudioClip(URL of file).play();
 
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.
 
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!