JLayer를 사용하여 Java로 미디어 플레이어를 만들었으며 mp3 파일을 사용할 수 있습니다. 사용자가 해당 노래를 재생하면 특정 노래에 대한 가사가 표시되지만, 이제는 가라오케처럼 노래에서 들리는 가사의 텍스트 색상을 강조하거나 변경하려고합니다. 하나의 노래에 대해서만이 작업을 수행하면됩니다. 이미 프로그램에서 가사를 구현할 것입니다. 이미이 작업을 수행하는 방법을 검색했지만 찾고있는 것을 정확하게 찾을 수없는 것 같습니다. 아래에서는 음악 파일을 재생하는 클래스에 코드를 추가했습니다. 고마워요!JLayer를 사용하여 mp3 파일 재생 (가라오케처럼)으로 가사를 강조 표시하는 방법
public class PlayMusic {
/**
* Global variables. FileInputStream obtains input bytes from a file system
* and reads streas of raw bytes. BufferedInputStream adds functionality
* to the fis, and creates an internal buffer array.
*/
private String filename;
private Player player;
private boolean canResume;
private boolean valid;
private int total;
private int stopped;
FileInputStream fis;
BufferedInputStream bis;
/**
* Constructor the takes in the path of the mp3 file to be played.
* @param filename - path of the mp3 file
*/
public PlayMusic(String filename) {
this.filename = filename;
this.canResume = false;
this.valid = false;
this.total = 0;
this.stopped = 0;
this.fis = null;
this.bis = null;
}
/**
* Function called to stop a song altogether as opposed to pausing.
*/
public void close() {
if (player != null)
player.close();
stopped = 0;
fis = null;
bis = null;
player = null;
canResume = false;
}
/**
* Function called to pause a song. Fis.available() is a method that returns
* the number of remaining bytes that can be read from the input stream.
*/
public void pause(){
try {
if (fis!=null)
stopped = fis.available();
if (player!= null)
player.close();
fis = null;
bis = null;
player = null;
if(valid)
canResume = true;
} catch (IOException e) {
}
}
/**
* Function called when we want to resume a song from where it left off
* after being paused.
*/
public void resume()
{
if(!canResume)
return;
if(play(total-stopped))
canResume = false;
}
/**
* Function called to play the song and keep track of where in the song the
* user presses stop in order for the resume button to work properly. Fis.skip
* skips over and discards pos bytes of data from fis.
* @param pos - The position of the song in which we want to resume play
* @return
*/
public boolean play(int pos) {
valid = true;
canResume = false;
try {
fis = new FileInputStream(filename);
total = fis.available();
if(pos> -1)
fis.skip(pos);
bis = new BufferedInputStream(fis);
player = new Player(bis);
}
catch (Exception e) {
System.out.println("Problem playing file " + filename);
System.out.println(e);
}
/**
* Run the play button in a new thread so the music plays in the background.
*/
new Thread() {
public void run() {
try { player.play(); }
catch (Exception e) { System.out.println(e); valid = false; }
}
}.start();
return valid;
}
}
하나의 노래에 대해서만 연주해야하는 경우 비디오 편집기를 사용하여 적절한 시간에 나타나는 하이라이트 가사의 비디오를 만드는 것이 좋습니다. – DJClayworth
[.srt] (http://en.wikipedia.org/wiki/SubRip#SubRip_text_file_format) 파일 형식과 같은 것을 사용하고 있습니까? – ggovan
@DJClayworth는 확실히 쉽게 할 수 있지만 프로그래밍 클래스의 최종 프로젝트를 진행하고 있으며 코딩을 통해이를 수행 할 수 있기를 원합니다. – user3078608