-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicPlayer.java
More file actions
61 lines (50 loc) · 1.48 KB
/
MusicPlayer.java
File metadata and controls
61 lines (50 loc) · 1.48 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
58
59
60
61
import javax.sound.sampled.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class mp3file {
public static void main(String[] args) {
String filePath = "src\\blueprint for the future - Lish Grooves.wav";
File file = new File(filePath);
try(Scanner sc=new Scanner(System.in);
AudioInputStream audiostream= AudioSystem.getAudioInputStream(file))
{
Clip clip=AudioSystem.getClip();
clip.open(audiostream);
clip.start();
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=sc.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");
}
}
//System.out.println("no problems detected");
}
catch(FileNotFoundException e){
System.out.println("audio file is not supports");
}
catch(UnsupportedAudioFileException e){
System.out.println("audio file is not supproted");
}
catch(LineUnavailableException e){
System.out.println("unable to access resource");
}
catch (IOException e){
System.out.println("something went wrong");
}
finally {
System.out.println("bye!");
}
}
}