This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Well, assuming that the user has a tool that will PLAY a .wav file (big assumption, platform dependant ) and has a mime type set up for .wav you can just execute it using Runtime.getRuntime().exec("whatever.wav");
"JavaRanch, where the deer and the Certified play" - David O'Meara
Joined: Nov 02, 2000
Thanks a lot, but I can't do this in a game. The file should play immediately.
Thanks again. This is a very bad way. I think it should going easier. I just want to play a sound file. Why must this so difficult? This I don't like in Java. I will try it. The next week I have no time.
Joined: Sep 29, 2000
You were thinking that it would play by magic in C++ or Visual Basic??? It didn't look so hard to me, and it's better than my idea.
Use Sun's mediaplayer bean. Downloadable from their website. Plays wav's, mp3's, mpeg's you name it. Once you get the package installed, it is very straight forward to work with. Here's a little snippet of my code for a ultra-thin jukebox, made in VAJ 3.5, after having imported the javax.media package: setMpb(new javax.media.bean.playerbean.MediaPlayer()); getMpb().setMediaLocation("file:///"+directory+file); getMpb().start(); This translates to something like this in a non-IDE environment(with imports and classpath correct): Mediaplayer mp = new Mediaplayer(); mp.setMediaLocation("file:///"+directory+file); mp.start();
Steffen Foldager<p>Sun Certified Java Programmer<br />Sun Certified Web Component Developer
Brain (Should that be "Brian"?), The AudioClip interface is what you want. It has three methods:
play() loop() stop()
I'm pretty sure that the only supported format for sound files is .au, although this may have changed in later versions of the JDK. It is a simple matter to save a .wav file as .au though. You can have multiple AudioClip objects playing at the same time, and they will be mixed together. Unfortunately, the sound is not actually loaded until the first time you call play(), so there is a slight delay that first time. But not on successive plays. You may be able to avoid the delay by using a MediaTracker object... Look both of these up in the API for more.
Java Acolyte in
Columbus, OH USA
[This message has been edited by ryan burgdorfer (edited March 22, 2001).]
Thanks all of you. I still have two questions. Then I use the beans, can I start the application still on every system without installing more then the jre? The audioclip is only for applets, or? If I try it on an application it is a bit difficult, right ??? Best regards.