Results 1 to 3 of 3
  1. #1
    Zepprock is offline Member
    Join Date
    Sep 2014
    Posts
    1
    Rep Power
    0

    Default Help with how to loop a sound

    I created a game but want some music in it, and as I write in the title i want the sound to loop. This is the code fore the sound class i have:

    Java Code:
    import java.applet.Applet;
    import java.applet.AudioClip;
    
    
    public class Sound {
    	
    		private AudioClip clip;
    		
    		//all sounds
    		public static final Sound ScoreSound = new Sound("/Score.wav");
    		public static final Sound BounceSound = new Sound("/Bounce.wav");
    		
    	
    		public Sound(String filename){
    			try{
    				clip = Applet.newAudioClip(Sound.class.getResource(filename));
    			}catch(Exception e){
    				e.printStackTrace();
    			}
    			
    		}
    
    		
    		public void play(){
    			try{
    				new Thread(){
    					public void run(){
    						clip.play();
    					}
    				}.start();
    				
    				}catch(Exception ex){
    					ex.printStackTrace();
    				}
    		}
    }
    All help appreciated :)

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Help with how to loop a sound

    Ever heard of the Java API aka javadocs?

    Java Platform SE 8

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

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Help with how to loop a sound

    This site might also help:

    Java Sound Resources
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Getting sound from sound card
    By crikey in forum Advanced Java
    Replies: 1
    Last Post: 06-18-2013, 09:07 AM
  2. Replies: 2
    Last Post: 11-07-2011, 02:25 AM
  3. Replies: 1
    Last Post: 10-01-2011, 02:12 AM
  4. Problems with sound in java and USB sound card
    By marblecatdog in forum New To Java
    Replies: 1
    Last Post: 04-19-2011, 12:02 PM
  5. Applets having sound
    By peiceonly in forum Java Applets
    Replies: 2
    Last Post: 03-31-2007, 09:55 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
  •