Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:
JavaWorld Daily Brew

audio in application works

Back to:
www.javaworld.com/javaworld/javatips/jw-javatip24.html
.

thanks!!! i have been looking for this because everyone just post about audio in applet this is great.
Only the continous audio doesn't work it says that the method start is not for that kind of stream.
Thanks a lot :)

Your rating: None Average: 2.5 (2 votes)

continuous stream

thanks sooooo much!! i really needed this code.

The code above for continuous playing has an error that it calls for play() instead of start().

Also there were some files which did not work with continuous but worked with single play. It's not simply the code cuz another file did play. Anyone have an idea?

Excuse me, but works this in RCPs too ?

Excuse me, but works this in RCPs too ?

Java

DOES NOT WORK!

you forgot Applet.newAudioClip(URL)?

newAudioClip(URL) is a static method in Applet Class, so it can easily be used in Applications as well.
e.g.
AudioClip ac = Applet.newAudioClip(url);
ac.play(); //play once
ac.stop(); //stop playing
ac.loop(); //play continuously

Here url can refer to some file within the jar file. So, this method is very useful.

only plays sound once

when you start up the program again the sound goes away.

Sorry, but...

Applet.newAudioClip(URL) does work, I tried it in an application:

try {
AudioClip ac = Applet.newAudioClip(new File(".\\sound.au").toURI().toURL());
ac.play();
}
catch(MalformedURLException e) {}

java.net.URI, java.net.URL and java.io.File are all required.

You can also use AudioClip.loop() aswell.

Thomas

where i put the sound file

in java, where i put the sound file?? if i want to call, how??

not working

not working

audiodata not working

how come the as.getdata() throws an exception

hai

hai

Another more standart way

Although you can't use AudioClip you can use the javax.sound.sampled.Clip interface:

Clip clickClip = AudioSystem.getClip();
AudioInputStream ais = AudioSystem.getAudioInputStream(waveFile);
clickClip.open(ais);
clickClip.loop(times - 1);
clickClip.start();

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <p> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br /> <br> <strike>
  • Lines and paragraphs break automatically.
  • Use <!--pagebreak--> to create page breaks.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
Just checking to see if you're an actual person rather than a spammer. Sorry for the inconvenience.