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

Discussion in 'Java' started by babo, Dec 5, 2005.

  1. babo

    babo Guest

    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
    babo, Dec 5, 2005
    #1
    1. Advertising

  2. babo wrote:
    > 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();

    --
    "Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
    Thomas Fritsch, Dec 5, 2005
    #2
    1. Advertising

  3. babo

    Roedy Green Guest

    On 5 Dec 2005 02:07:21 -0800, "babo" <> wrote,
    quoted or indirectly quoted someone who said :

    >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
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Dec 5, 2005
    #3
  4. babo

    babo Guest

    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___






    Thomas Fritsch wrote:
    > babo wrote:
    > > 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
    >
    babo, Dec 6, 2005
    #4
  5. babo wrote:
    > 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;

    --
    "Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
    Thomas Fritsch, Dec 6, 2005
    #5
  6. babo wrote:
    > 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")

    --
    "Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
    Thomas Fritsch, Dec 6, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?R2lhbmNhcmxv?=

    debug Windows app works but, not web app

    =?Utf-8?B?R2lhbmNhcmxv?=, Sep 26, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    314
    =?Utf-8?B?R2lhbmNhcmxv?=
    Sep 26, 2005
  2. Krista
    Replies:
    3
    Views:
    2,302
    Andrew Thompson
    Sep 15, 2004
  3. Archana
    Replies:
    1
    Views:
    1,371
    Andrew Thompson
    Oct 25, 2004
  4. Luc The Perverse

    Sound Quality In Sound API

    Luc The Perverse, Oct 30, 2005, in forum: Java
    Replies:
    4
    Views:
    1,471
    Andrew Thompson
    Oct 31, 2005
  5. Replies:
    0
    Views:
    495
Loading...

Share This Page