-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMusic.java
37 lines (29 loc) · 879 Bytes
/
Music.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//package com.mycompany.playmusicjavasupersimple;
import java.io.File;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.JOptionPane;
public class Music {
public Music(){
try {
File musicPath = new File("src/main/spice.wav");
if (musicPath.exists()) {
AudioInputStream audioInput = AudioSystem.getAudioInputStream(musicPath);
Clip clip = AudioSystem.getClip();
clip.open(audioInput);
clip.start();
}
else {
System.out.println("The spice.wav audio does not exist");
}
}
catch (Exception e) {
}
}
/*public static void main(String[] args) {
String path = "src/main/images/spiceeeeee.mp3";
PlayMusic(path);
JOptionPane.showMessageDialog(null, "Press OK to play music");
}*/
}