0
자바로 Audioplayer를 가지고 있습니다. 현재 재생중인 노래에 대한 정보를 인쇄하고 싶지만 제대로 작동하지 않는 것 같습니다. 어떻게해야합니까? 자세한 정보가 필요하면 알려주십시오.JAVA Netbeans - 현재 재생중인 노래를 인쇄하는 방법
MOSKITO-X의 조언 @ 다음
package BLL;
import java.util.Scanner;
public class SoundControlMenu extends Menu {
AudioPlayer p;
final String fileA = "hi";
/**
*
*/
public SoundControlMenu() {
super(" Sound Controls",
"|Play |",
"|Pause |",
"|Resume |",
"|Stop |",
"|Now playing |");
}
/**
* @param option
* @void prints the SoundControlMenu
*/
@Override
protected void doAction(int option) {
switch (option) {
case 0:
if (p != null) {
p.stop();
}
break;
case 1:
Scanner scanner = new Scanner(System.in);
App.Menu.getInstance().showSongs();
System.out.println("Enter song title:");
String chooseSong = scanner.nextLine();
chooseSong = chooseSong.replace(" ", "");
if (p != null) {
p.stop();
}
p = new AudioPlayer(chooseSong + ".mp3");
if (p.isValid() == false) {
System.out.println("The audio player is not working -- " + p.getErrorMessage());
} else {
p.startToPlay();
}
break;
case 2:
if (p != null) {
p.pause();
}
break;
case 3:
if (p != null) {
p.resume();
}
break;
case 4:
if (p != null) {
p.stop();
}
break;
case 5:
if (p == null) {
System.out.println("No audio player exist...");
} else if (p.isPlaying()) {
System.out.println(fileA);
} else {
System.out.println("NOT playing...");
}
}
}
}
1.)'chooseSong'을'fileA' 또는 2.로 대체하십시오.)'chooseSong = chooseSong.replace ("", "");'다음에'fileA = chooseSong;'3. 다음에 놓으십시오. 공백은'chooseSong.replace' 위에 놓습니다. –
대단히 감사합니다. @ moskito-x! 나는 1) 처음 시도했지만 작동하지 않았다. 'variable fileA가 초기화되지 않았을 수 있습니다. '라는 오류 메시지가 표시되어 완벽하게 작동하는 2)로 넘어갔습니다. 다시 한 번 감사드립니다! 이 사이트의 새로운 기능 - 귀하의 의견을 "답변"으로하려면 어떻게해야합니까? – Christopher
자신의 질문에 대답하십시오. 당신이 일하기 위해 무엇을했는지 적어주십시오. 언젠가는 당신의 대답을 받아들입니다. –