Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Playing sound each time mouse is clicked (not working)

  1. #1
    Junior Member
    Join Date
    May 2012
    Location
    Portland, OR
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Playing sound each time mouse is clicked (not working)

    Hey guys, I'm really stumped. I have a chat program and figured it'd be nice to add sound alerts for new messages, but it's not playing sound at all now.
            private class AudioClip extends Thread implements ActionListener{		
    		private InputStream in;
    		private AudioStream as;
     
    		public void run(){
     
    		        //Open audio stream
    			try{
    				in = new FileInputStream("alert.wav");
    				as = new AudioStream(in);
    				AudioPlayer.player.start(as);
     
    				Timer time = new Timer(5000, this);
    				time.setRepeats(false);
    				time.start();
     
    			}catch(FileNotFoundException e){
    				e.printStackTrace();
    			}catch (IOException e){
    				e.printStackTrace();
    			}
    		}
     
    		public void actionPerformed(ActionEvent event) {
    			AudioPlayer.player.stop(as);
    		}
    	}

    This is in the chat portion and happens each time a message pops up:
            if(playAudio){
    		new AudioClip();						
    	}

    EDIT: Got it! I was in a hurry and forgot '.start()' haha
    Last edited by BestSanchez; August 24th, 2012 at 10:24 PM. Reason: SOLVED


Similar Threads

  1. pause while playing sound
    By huddo in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 23rd, 2012, 08:33 PM
  2. Playing sound in my nursing program
    By loui345 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 19th, 2012, 08:26 PM
  3. Replies: 9
    Last Post: February 20th, 2012, 04:02 PM
  4. Playing sound in an applet
    By Skyhigh32 in forum Java Theory & Questions
    Replies: 1
    Last Post: June 3rd, 2011, 07:41 AM
  5. playing sound using java
    By sdhilipan89 in forum Java Applets
    Replies: 6
    Last Post: March 25th, 2010, 08:59 AM