-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
57 lines (51 loc) · 1.92 KB
/
Copy pathMain.java
File metadata and controls
57 lines (51 loc) · 1.92 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
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 Main {
public static void main(String[] args) {
String filePath = "idk.wav";
File file = new File(filePath);
try(Scanner scanner = new Scanner(System.in);
AudioInputStream audioStream = AudioSystem.getAudioInputStream(file)){
Clip clip = AudioSystem.getClip();
clip.open(audioStream);
String response = "";
while(!response.equals("Q")){
System.out.println("P = Play");
System.out.println("S = Stop");
System.out.println("R = Reset");
System.out.println("Q = Quit");
System.out.print("Enter Your choice: ");
response = scanner.next().toUpperCase();
switch(response){
case "P" -> clip.start();
case "S" -> clip.stop();
case "R" -> clip.setMicrosecondPosition(0);
case "Q" -> clip.close();
default -> System.out.println("Invalid Choice!");
}
}
}
catch(FileNotFoundException e){
System.out.println("Could not locate file");
}
catch(UnsupportedAudioFileException e){
System.out.println("Audio file is not supported");
}
catch(LineUnavailableException e){
System.out.println("Unable to access audio resource");
}
catch(IOException e){
System.out.println("Something went wrong");
}
finally{
System.out.println("Bye!");
}
}
}