Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
babo - 05 Dec 2005 10:07 GMT
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
Thomas Fritsch - 05 Dec 2005 13:33 GMT
> 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(jav
a.net.URL
)

> just for the beggining of the program??
Call
  clip.play();
> or it can play all the time?
Call
  clip.loop();

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

babo - 06 Dec 2005 15:33 GMT
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___

> > how can I import or load a *.wav or any sound clip i JAVA application
> Load it from anywhere
[quoted text clipped - 5 lines]
> static method, it should be possible to call it from outside an
> applet, too. See also
Thomas Fritsch - 06 Dec 2005 15:39 GMT
> 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;

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

Thomas Fritsch - 06 Dec 2005 15:54 GMT
>  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")

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

Roedy Green - 05 Dec 2005 18:13 GMT
>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?

see http://mindprod.com/jgloss/sound.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.