Created
December 22, 2023 22:54
-
-
Save System3-2/a6994d0aa8619d998053f4eca6814c7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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