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
Smilidon Sapiens
Ranch Hand
Joined: Nov 02, 2000
Posts: 66
posted
0
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.
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
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.
Hi, Brian. I don't know if this will help you or not, but have a look at Karl Hornell's technical notes regarding one of his music-playing applets. Good luck. Art
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.
------------------
Ryan Burgdorfer
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.
Steffen Foldager
Ranch Hand
Joined: Mar 22, 2001
Posts: 58
posted
0
AudioClip only plays sun's .au format, which is a pretty poor 8-bit one. And yes, once you get the jre installed right, it's pretty straght forward from there. (That, and finding the damn jars, was the hard part for me). All the info you need at: http://java.sun.com/products/java-media/jmf/2.1.1/playerbean.html Have fun..
Steffen Foldager
Ranch Hand
Joined: Mar 22, 2001
Posts: 58
posted
0
Ahem, that's the jre for the MediaPlayerBean, off course.
ryan burgdorfer
Ranch Hand
Joined: Jan 24, 2001
Posts: 219
posted
0
AudioClip should work the same in both applets and applications, I believe... ------------------