Results 1 to 2 of 2
  1. #1
    qwert_zuiopŁ is offline Member
    Join Date
    May 2012
    Posts
    1
    Rep Power
    0

    Default AudioClip does not work

    Hello,

    I want to use audioclips in my program, but it does not work the way I use it. Here is my code:

    Java Code:
    public class AudioTest {
        public static void main(String[] args) {
            new method();
        }
    }
     
    class method implements Runnable {
        AudioClip right,wrong;
        public method() {
            right = Applet.newAudioClip(getClass().getResource("right.wav"));
            wrong = Applet.newAudioClip(getClass().getResource("wrong.wav"));
            Thread th=new Thread(this);
            th.start();
        }
        public void run() {
            while(true) {
                System.out.println("runs");
                        wrong.play();
                try{Thread.sleep(1000);}catch(InterruptedException err){System.out.println(err.toString());}
                        right.play();
                try{Thread.sleep(1000);}catch(InterruptedException err){System.out.println(err.toString());}
            }
        }
    }
    I sometimes get just a single "runs" as output as well as two times "runs". The sound plays respectively one or two times.

    What am I doing wrong?
    Thanks!!

    EDIT: I just made the code runnable ;). @DarrylBurke: Sorry, did not adjust all the names correctly (I am german and wanted to translate the names)
    Last edited by qwert_zuiopŁ; 05-30-2012 at 03:54 PM.

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

    Default Re: AudioClip does not work

    Quote Originally Posted by qwert_zuiopŁ View Post
    Here is my code:

    Java Code:
    ...
            new methode();
    ...
    class method
    
    ...
    ...
        public Methode() {
    What am I doing wrong?
    Posting absurdly uncompilable code and claiming it runs.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-13-2011, 10:28 PM
  2. AudioClip: Sound file format?
    By CoderMan in forum Java Applets
    Replies: 3
    Last Post: 07-04-2010, 12:29 AM
  3. AudioClip
    By jon80 in forum New To Java
    Replies: 10
    Last Post: 06-13-2009, 07:10 PM
  4. Volume of AudioClip
    By Fedor in forum New To Java
    Replies: 0
    Last Post: 04-25-2009, 04:16 PM
  5. Applet-Image,audioclip problem-pls help
    By samares in forum Java Applets
    Replies: 1
    Last Post: 02-21-2009, 03:23 AM

Posting Permissions

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