Skip to content

Instantly share code, notes, and snippets.

@System3-2
Created December 22, 2023 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save System3-2/a6994d0aa8619d998053f4eca6814c7e to your computer and use it in GitHub Desktop.
Save System3-2/a6994d0aa8619d998053f4eca6814c7e to your computer and use it in GitHub Desktop.
import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args)throws UnsupportedAudioFileException, IOException, LineUnavailableException {
Scanner scanner = new Scanner(System.in);
File file = new File("C:\\Users\\Oloja\\Downloads\\flex.wav");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
String response = "";
while(!response.equals("Q")) {
System.out.println("P = play, S = Stop, R = Reset, Q = Quit");
System.out.println("Enter your choice: ");
response = scanner.next();
response = response.toUpperCase();
switch (response) {
case ("P"): clip.start();
break;
case ("S"): clip.stop();
break;
case ("R"): clip.setMicrosecondPosition(0);
break;
case ("Q"): clip.close();
break;
default:
System.out.println("Not a valid response");
}
}
clip.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment