Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple example of playing a sound?



Three options I can think of here.

The simpliest is to use the Applet.play().
http://java.sun.com/j2se/1.4.2/docs/api/java/applet/Applet.html#play(java.net.URL)

URL soundUrl = new URL("file://sound.wav");
AudioClip audioClip = Applet.newAudioClip(soundUrl);
audioClip.play();


Next level of complexity is to use the javax.sound.sampled.* classes.
http://java.sun.com/j2se/1.4.2/docs/api/javax/sound/sampled/package-summary.html

URL soundUrl = new URL("file://sound.wav");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundUrl);
DataLine.Info info = new DataLine.Info(Clip.class,
audioInputStream.getFormat());
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(audioInputStream);
clip.start();


And third would be to download the Java Media Framework (JMF)
http://java.sun.com/products/java-media/jmf/

URL soundUrl = new URL("file://sound.wav");
Player player = Manager.createPlayer(soundUrl);
player.start();


-jdr

--- Alexander Lamb <email@hidden> wrote:
> Hello,
>
> I need to play a simple sound when some events happen in my app. In Java I
> see there is the beep function but this is too simple. On the other hand, the
> sound API seems over complicated as I only need to play two or three simple
> sounds.
>
> 1. Is there a simple way to just say something like "(new
> Sound("soundFile.??")).play()"
>
> 2. Where can I find sound files for the kind of sounds you would hear in
> sci-fi movie when a screen is filling up with data "smallish beeps",
> "rings...", etc... It is too be used as user feedback when either an action
> succeeded or failed or when the UI updates from behind the scenes without
> user interraction.
>
> Thanks a lot,
>
> Alex
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Simple example of playing a sound? (From: Alexander Lamb <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.