sound in a JAVA app (but not in applet)-how to load

B

babo

how can I import or load a *.wav or any sound clip i JAVA application

just for the beggining of the program??
or it can play all the time?

thnx
 
T

Thomas Fritsch

babo said:
how can I import or load a *.wav or any sound clip i JAVA application
Load it from anywhere
URL url = new URL("http://....../ping.wav");
or load it from your classpath:
URL url = getClass().getResource("/..../ping.wav");
AudioClip clip = Applet.newAudioClip(url);
Yes, I know it is a method of class Applet. But because it is a
static method, it should be possible to call it from outside an
applet, too. See also
http://java.sun.com/j2se/1.4.2/docs/api/java/applet/Applet.html#newAudioClip(java.net.URL)
just for the beggining of the program?? Call
clip.play();
or it can play all the time?
Call
clip.loop();
 
B

babo

public static void main ( String[] args )
{
URL url = new URL("http://marvin.kset.org/~babo/sound/tada.wav");


//URL url =
getClass().getResource("file:c:/windows/Media/ping.wav");
AudioClip clip = Applet.newAudioClip(url);
clip.loop();
}




it says>
Exception in thread "main" java.lang.Error: Unresolved compilation
problems:
URL cannot be resolved to a type
URL cannot be resolved to a type

at Play.main(Play.java:25)


whyyyyy___
 
T

Thomas Fritsch

babo said:
Exception in thread "main" java.lang.Error: Unresolved compilation
problems:
URL cannot be resolved to a type

It seems you forgot
import java.net.URL;
 
T

Thomas Fritsch

babo said:
public static void main ( String[] args )
{
URL url = new URL("http://marvin.kset.org/~babo/sound/tada.wav");


//URL url =
getClass().getResource("file:c:/windows/Media/ping.wav");
By the way:
The above line doesn't make sense. Either you mean
URL url = new URL("file:///c:/windows/Media/ping.wav");
or
URL url = new URL("file:/c:/windows/Media/ping.wav");
or
URL url = getClass().getResource("/com/yourcompany/media/ping.wav");
(assuming your .wav file is located besides the .class files of package
"com.yourcompany.media")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top