//ファイルの入出力を行う import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; //mp3ファイルの再生 import javazoom.jl.decoder.*; import javazoom.jl.player.*; public class SoundTestMp3 { private Player player; private BufferedInputStream stream; public void play(String file) throws JavaLayerException, FileNotFoundException { stream = new BufferedInputStream((new FileInputStream(file))); player = new Player(stream); player.play(); //再生 } public void close() throws IOException { if (player != null) { player.close(); //プレイヤーを閉じる } if (stream != null) { stream.close(); //ストリームを閉じる } } public static void main(String[] args) { SoundTestMp3 player = new SoundTestMp3(); try { player.play("test.mp3"); //音声ファイルの指定 } catch (FileNotFoundException e) { e.printStackTrace(); } catch (JavaLayerException e) { e.printStackTrace(); } finally { if (player != null) { try { player.close(); } catch (IOException e) { e.printStackTrace(); } } } } }