Java audio 🔊

Published: 18 October 2020
on channel: Bro Code
119,854
3.7k

Java audio sound music player tutorial explained

#java #audio #sound #music

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import javax.sound.sampled.*;

public class Main {

public static void main(String[] args) throws UnsupportedAudioFileException, IOException, LineUnavailableException{

Scanner scanner = new Scanner(System.in);

File file = new File("Level_Up.wav");
AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
Clip clip = AudioSystem.getClip();
clip.open(audioStream);

String response = "";


while(!response.equals("Q")) {
System.out.println("P = play, S = Stop, R = Reset, Q = Quit");
System.out.print("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");
}

}
System.out.println("Byeeee!");
}
}


On this page of the site you can watch the video online Java audio 🔊 with a duration of hours minute second in good quality, which was uploaded by the user Bro Code 18 October 2020, share the link with friends and acquaintances, this video has already been watched 119,854 times on youtube and it was liked by 3.7 thousand viewers. Enjoy your viewing!