Advertisement
Guest User

Untitled

a guest
Sep 1st, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.net.URL;
  3.  
  4. import javax.sound.sampled.AudioInputStream;
  5. import javax.sound.sampled.AudioSystem;
  6. import javax.sound.sampled.Clip;
  7.  
  8. public class Main {
  9.  
  10. public static void main(String[] args) {
  11. AudioInputStream inputStream = null;
  12. Clip clip = null;
  13. try {
  14. inputStream = AudioSystem.getAudioInputStream(new URL("http://www.imageandart.com/sonidos/alarma.wav"));
  15. clip = AudioSystem.getClip();
  16. clip.open(inputStream);
  17.  
  18. clip.start();
  19. System.out.println("Audio is playing: " + clip.isRunning() + " active: " + clip.isActive() + " open: " + clip.isOpen());
  20. while (clip.isRunning()) {
  21. Thread.sleep(500);
  22. }
  23. clip.flush();
  24. clip.stop();
  25. } catch (Exception e) {
  26. e.printStackTrace();
  27. } finally {
  28. try {
  29. if (clip != null) {
  30. clip.close();
  31. }
  32. if (inputStream != null) {
  33. inputStream.close();
  34. }
  35. } catch (IOException e) {
  36.  
  37. } finally {
  38. inputStream = null;
  39. clip = null;
  40. }
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement