-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayMusic.java
More file actions
36 lines (26 loc) · 846 Bytes
/
PlayMusic.java
File metadata and controls
36 lines (26 loc) · 846 Bytes
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
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
public class PlayMusic {
public static void RunMusic(String song){
try{
AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(song));
Clip clip = AudioSystem.getClip();
clip.open(inputStream);
clip.loop(0);
}
catch(UnsupportedAudioFileException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
catch(LineUnavailableException e){
e.printStackTrace();
}
}
}