Playing .mp3 and .wav in Java?

前端 未结 14 2107
一整个雨季
一整个雨季 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:48

    you can play .wav only with java API:

    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.Clip;
    

    code:

    AudioInputStream audioIn = AudioSystem.getAudioInputStream(MyClazz.class.getResource("music.wav"));
    Clip clip = AudioSystem.getClip();
    clip.open(audioIn);
    clip.start();
    

    And play .mp3 with jLayer

提交回复
热议问题