• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Play a .wav file

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use Applet.newAudioClip(URL of file).play();
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic