Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

playing sound files

Status
Not open for further replies.

guestUser1234

Technical User
Apr 1, 2001
3
CA
I'm trying to get a sound file to play in my applet. It works great, but when i upload it to the server, the sound files won't play. I've looked everywhere for the answer. Am i supposed to load the sound files with the html?

This is what i've tried that does NOT work:

win=Applet.newAudioClip(new URL(getCodeBase(),"oops.wav"));
win.play();

this also does not work:

wrong=this.getAudioClip(new URL(getCodeBase(),"splat.wav"));
wrong.play();


I'm confused.
 
Ok. I've changed the sound files to .au clips. It still won't work. I have also changed the sound to load in the init() method. I have changed the code to:

win=getAudioClip(getCodeBase(),"CodeBrain006.au");

and it STILL doesn't work. I'm sure it has something to do with HTML <PARAM> tags, but i don't know how to use them. can anyone help?
 
The sound file does need to be loaded to the server. I wasn't sure from your message whether you had done that. Also, does your sound file live in the root directory of the web server? I might be wrong, and I haven't tested it, but getCodeBase() looks like it gets the root URL of the server (i.e. but not the directory on the server (i.e. so you might need to provide the relative path in the second argument.

Give that a shot, and let me know whether it works. If I have time today, I'll do the same.
 
I have the same problem. Somebody told me we have to import java.net.*, did you do that?
 
No, you do not have to import java.net.*. The Applet class found in java.awt.applet.* has a AudioClip class which you can use. It will play .au files. .wav files in Java 2.

wrong=this.getAudioClip(new URL(getCodeBase(),&quot;splat.wav&quot;));

getAudioClip() returns the AudioClip for a sound file located by a URL. getCodeBase() will return the URL object for the location of the .class file for your applet. Just make sure you put your sound files in the same folder Path as this class on your Server.

Or if it is easier, use the getDocumentBase(). It will return the URL object location of the .html used for your applet on the Server. Put your sound files in the same folder.

Hope this helps. Good luck,
Brian
 
I've had the same problem! when I test the applet at home, it works. From my webpage it craps out. the applet has 5 radio buttons; 4 to play various .wav files, 1 to stop the music. To test other's suggestions, I added labels to the applet to show me results:
(I used X's below instead of appropriate letters to avoid the appearance of a link within this post)

URL url1 = new URL(&quot;htXp://wXw.~~~.org/song1a.wav&quot;);
audioClip1 = getAudioClip(url1);
lbl1.setText(&quot;url1= &quot; + url1);
[on applet shows url1= htXp://wXw.~~~.org/song1a.wav]

audioClip2 = getAudioClip(getDocumentBase(), &quot;song1b.wav);
lbl2.setText(&quot;audioClip2= &quot; + audioClip2);
[on applet shows audioClip2= class.com.ms.vm.loader.URLAudioClip[null]

the next two lines give the same result as audioClip2
audioClip3 = getAudioClip(new URL(getCodeBase(), &quot;song1c.wav&quot;));

this code is inside a try/catch block, with a label on the applet to show when an error is caught(no).
I upload .html, .jpg, .class and .wav files to the web site the same way, so I think they are all in the same folder.
This is for my church, so I really want to get it working. Does anyone have any other suggestions?!
 
My applet sound works now, but only once I switched to .au sound files.

The problem is that you have to ensure that your browser supports JDK 1.2, which it probably doesn't. You can either switch to .au sound files for JDK 1.1, or you can go to the following URL and it explains how to run the JDK 1.2 interpreter on a user's machine.


&quot;Although the above code is simple and no expert coding is required to play the new audio format, no present version of any browser directly supports the JDK 1.2 applet rendering. For that purpose, you need to install the JDK 1.2 Plug-in in the user system. &quot;
 
AOL browser does support Java 1.2, but a majority of your users will be using Netscape or Microsoft IE. Therefore, if you want to use Swings and wav files you will have to use the JDK 1.2 Plug-IN as guestUser1234 has stated.

It really makes me mad that these have not been upgraded in these browsers, but they are competitors of Sun. It is a pain because even with the plug ins, the user will be prompted to load the plug in to over ride the browser. Not very freindly for the user.

I find myself using the old awt gui and au sound files because of this.

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top