- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
Latest commit
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
importjava.io.File;
importjava.io.FileNotFoundException;
importjava.io.IOException;
importjava.util.Scanner;
importjavax.sound.sampled.AudioInputStream;
importjavax.sound.sampled.AudioSystem;
importjavax.sound.sampled.Clip;
importjavax.sound.sampled.LineUnavailableException;
importjavax.sound.sampled.UnsupportedAudioFileException;
publicclassMain {
publicstaticvoidmain(String[] args) {
StringfilePath = "idk.wav";
Filefile = newFile(filePath);
try(Scannerscanner = newScanner(System.in);
AudioInputStreamaudioStream = AudioSystem.getAudioInputStream(file)){
Clipclip = AudioSystem.getClip();
clip.open(audioStream);
Stringresponse = "";
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(FileNotFoundExceptione){
System.out.println("Could not locate file");
}
catch(UnsupportedAudioFileExceptione){
System.out.println("Audio file is not supported");
}
catch(LineUnavailableExceptione){
System.out.println("Unable to access audio resource");
}
catch(IOExceptione){
System.out.println("Something went wrong");
}
finally{
System.out.println("Bye!");
}
}
}