オーディオを再生するスレッドがありますが、フォームを閉じるときに、プレーヤーがオーディオ ファイルを再生するのを停止したい場合、スレッドの実行方法は次のとおりです。
public static Player playplayer;
public static FileInputStream fis;
public static BufferedInputStream bis;
public void run(){
while(!Thread.currentThread().isInterrupted()){
try{
String file="E://Net Beans Work Space//The Imran's Regression"
+ "//src//imranregression//audio//iron man.mp3";
fis= new FileInputStream(file);
bis= new BufferedInputStream(fis);
playplayer = new Player(bis);
playplayer.play();
}catch(Exception e){
System.out.print("ERROR "+e);
}
}
私がやっていることを私のプレーヤーを止める私の方法は次のとおりです:
private void formWindowClosing(java.awt.event.WindowEvent evt) {
try{
BGMusic.fis.close();
BGMusic.bis.close();
BGMusic.playplayer.close(); //want to close my player here
audioplay.interrupt(); //stopping my thread here
}catch(Exception e){
return;
}
}
問題は、スレッドを停止したり、オーディオの再生を停止したりするために、私がやりたいことをしていなかったということです。どうすればこれを達成できますか? 助けてくださいよろしくお願いします!