Results 1 to 3 of 3

Thread: [RESOLVED] How can I play sounds in Java?

  1. #1

    Thread Starter
    Addicted Member MoE70's Avatar
    Join Date
    May 2006
    Posts
    185

    Resolved [RESOLVED] How can I play sounds in Java?

    Im making a game and i want to make a sounds class so i can call different sounds from different classes for example

    Sounds.play1upSound();

    how can i make a sound class? (for .wav mainly)


    thanks
    Last edited by MoE70; Apr 16th, 2009 at 06:12 PM.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: How can I play sounds in Java?

    The following sample code might be helpful. I know java has a sound API but this is the easiest way to play a sound file
    Code:
    import java.net.MalformedURLException;
    
    public class Test {
    	public static void main(String[] args) throws MalformedURLException {
    		java.applet.AudioClip clip = java.applet.Applet
    				.newAudioClip(new java.net.URL(args[0]));
    		clip.play();
    	}
    }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Addicted Member MoE70's Avatar
    Join Date
    May 2006
    Posts
    185

    Re: How can I play sounds in Java?

    thanks

Posting Permissions

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



Click Here to Expand Forum to Full Width