Advertisement
Guest User

main.java

a guest
Jul 24th, 2014
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. package test.sound;
  2.  
  3. import javax.sound.sampled.AudioInputStream;
  4. import javax.sound.sampled.AudioSystem;
  5. import javax.sound.sampled.Clip;
  6.  
  7. public class main {
  8.  
  9.         public static void main(String[] args) {
  10.                playSound("/path/to/sounds/");
  11.    
  12.         }
  13.         public static synchronized void playSound(final String url) {
  14.                   new Thread(new Runnable() {
  15.                   // The wrapper thread is unnecessary, unless it blocks on the
  16.                   // Clip finishing; see comments.
  17.                     public void run() {
  18.                       try {
  19.                         Clip clip = AudioSystem.getClip();
  20.                         AudioInputStream inputStream = AudioSystem.getAudioInputStream(
  21.                           main.class.getResourceAsStream(url));
  22.                         clip.open(inputStream);
  23.                         clip.start();
  24.                       } catch (Exception e) {
  25.                         System.err.println(e.getMessage());
  26.                       }
  27.                     }
  28.                   }).start();
  29.                 }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement