Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.net.URL;
- import javax.sound.sampled.AudioInputStream;
- import javax.sound.sampled.AudioSystem;
- import javax.sound.sampled.Clip;
- public class Main {
- public static void main(String[] args) {
- AudioInputStream inputStream = null;
- Clip clip = null;
- try {
- inputStream = AudioSystem.getAudioInputStream(new URL("http://www.imageandart.com/sonidos/alarma.wav"));
- clip = AudioSystem.getClip();
- clip.open(inputStream);
- clip.start();
- System.out.println("Audio is playing: " + clip.isRunning() + " active: " + clip.isActive() + " open: " + clip.isOpen());
- while (clip.isRunning()) {
- Thread.sleep(500);
- }
- clip.flush();
- clip.stop();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (clip != null) {
- clip.close();
- }
- if (inputStream != null) {
- inputStream.close();
- }
- } catch (IOException e) {
- } finally {
- inputStream = null;
- clip = null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement