Results 1 to 4 of 4
  1. #1
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default Playing Sound Effects in Java

    As the title says, how could I play sound effects in Java?

    Let's say I have a sound file (*.wav) on my computer. What methods to I need to do to declare something to that .wav file? Also, what imports would I need?

    How can I play the sound, afterwards? Loop it? Stop it?

    Thanks for the help, and if this information seems too simple or generic, is there a tutorial I could see or a very concise example I could look at?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,237
    Rep Power
    19

    Default Re: Playing Sound Effects in Java

    Check the Applet API looking for static methods, and/or search for JMF (Java Media Framework)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Aash96 is offline Member
    Join Date
    Dec 2012
    Posts
    26
    Rep Power
    0

    Default Re: Playing Sound Effects in Java

    JMF is mainly used for adding videos, here is the code i have come up with and it works:


    import java.applet.Applet;
    import java.applet.AudioClip;
    import java.net.URL;

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author Aashish Bharat
    */
    public class Music{
    public String ml = "fray.wav";
    public Music(String s)
    {
    ml = s;
    }
    URL urlClick = welcome.class.getResource(ml);
    AudioClip click = Applet.newAudioClip(urlClick);
    public void loop()
    {
    click.loop();
    }
    public void stop()
    {
    click.stop();
    }
    public void start(String s)
    {
    click.play();
    }
    }

  4. #4
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default Re: Playing Sound Effects in Java

    Thank you very much. I'll take a look at this sometime when I'm free.

Similar Threads

  1. sound playing
    By nikkka in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-10-2011, 05:38 PM
  2. playing sounds with the javax.sound package
    By hannes in forum Advanced Java
    Replies: 8
    Last Post: 05-27-2010, 06:45 PM
  3. Re-playing sound
    By JSK in forum CLDC and MIDP
    Replies: 0
    Last Post: 02-06-2008, 11:34 AM
  4. Playing sound in applet??????
    By Bagesh in forum Java Applets
    Replies: 2
    Last Post: 07-13-2007, 04:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •