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 Mar 22, 2001 07:11:00

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 Mar 22, 2001 10:54:00

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.

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();

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).]

<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>

Smilidon Sapiens
Ranch Hand

Joined: Nov 02, 2000
Posts: 66

posted Mar 23, 2001 01:29:00

0

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.