我尝试制作一个播放 FLAC 文件的类。为此,我使用jFlac。所以,为了播放一首歌,我需要做:
Player p = new Player();
p.decode("PATH_TO_FLAC");
我把它放在我班级的 run() 方法中。如果我启动线程,那就行了。但我想知道如何暂停。我无法控制 in 中的循环p.decode();
,所以我不能使用等待和通知。但Thread.suspend()
已弃用。我不知道该怎么办。
我的课:
public class FLACPlayer implements Runnable {
/**
* Path of the song
*/
private String file;
private org.kc7bfi.jflac.apps.Player player;
/**
* The thread launching the player
*/
private Thread playerThread;
/**
* Constructor: initialize the player
*
* @param str
* The path of the file to play
*/
public FLACPlayer(String str) {
file = str;
player = new org.kc7bfi.jflac.apps.Player();
this.playerThread = new Thread(this, "AudioPlayerThread");
}
public void play() {
playerThread.start();
}
@Override
public void run() {
try {
player.decode(file);
} catch (IOException | LineUnavailableException e) {
}
}
谢谢!