English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need to play a mid file in a java applet and I can not find any info on why my sound will not play I have the following code in my program:

URL uwhere;
uwhere = getDocumentBase ();
audio = getAudioClip (uwhere, "C:\Documents and Settings\usernamehere\Desktop\webapp\beetlejuiceR");
audio.play ();

From what I have seen this coding is correct but if still generates errors. The errors are that the \ are a unknown symbol. Do I need different code (if so please post the correct code) or is there a error that I can not see (if so please post how to fix the error) .

2006-09-28 11:58:40 · 3 answers · asked by thexlaw 2 in Computers & Internet Programming & Design

3 answers

You cannot play a mid or midi file using AudioClip instance; AudioClip can play 8 KHz .AU format audio. You must create your own classes or download classes to play other formats using java. If you don't want to program or search for those classes, you can convert your midi file into a .AU file or even record your midi file into a .wav and then, you can use some converter like SoundEdit to convert your new .wav into a new .AU; and your problem will be solved.

2006-09-28 13:14:33 · answer #1 · answered by sonfarX 4 · 0 0

You're seeing the "\" error because Java doesn't really understand Windows paths. You probably want to convert that to a URL. See the link below for more info on this.

But more generally, if you're running an Applet it won't be able to access your local filesystem. This is by design of the 'sandbox' in which an Applet runs for security reasons. You may get around this by signing the Applet or passing it a real Internet URL to the clip to play.

2006-09-28 12:09:13 · answer #2 · answered by Dr.Mr.Ed 5 · 0 0

getAudioClip() uses the two arguments to construct the full URL, so from your code it is taking the file URL to your HTML document, and then trying to append the String you passed in as the second. That won't be a properly formatted URL.

The second argument should be the relative path from the document base URL to the audio file. So if your audio file is in the same directory as the HTML doc, just pass the name of the file. If it is in a sub-path, like maybe an "audio" subdirectory, pass in the relative path, e.g. getAudioClip(uwhere, "audio/myAudioClip.mid"). Also note that you could use getCodeBase() to get the base URL for the applet class file, in cases where the audio file is stored relative to the applet class file vice relative to the HTML document.

You won't get a security violation because the audio file is being requested from the same "domain" as the document and/or applet code.

I'm adding this reference: http://java.sun.com/products/java-media/sound/techReference/javasoundfaq.html#formats
and this one:
http://java.sun.com/developer/technicalArticles/Media/soundbarrier/index.html
in response to another poster that stated contrary out-of-date (Java 1.1) information.

2006-09-28 12:28:28 · answer #3 · answered by vincentgl 5 · 0 0

fedest.com, questions and answers