Playing .mp3 and .wav in Java?

前端 未结 14 2326
一整个雨季
一整个雨季 2020-11-22 06:52

How can I play an .mp3 and a .wav file in my Java application? I am using Swing. I tried looking on the internet, for something like this example:<

14条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 07:32

    Use this library: import sun.audio.*;

    public void Sound(String Path){
        try{
            InputStream in = new FileInputStream(new File(Path));
            AudioStream audios = new AudioStream(in);
            AudioPlayer.player.start(audios);
        }
        catch(Exception e){}
    }
    

提交回复
热议问题