Playing .mp3 and .wav in Java?

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

    To give the readers another alternative, I am suggesting JACo MP3 Player library, a cross platform java mp3 player.

    Features:

    • very low CPU usage (~2%)
    • incredible small library (~90KB)
    • doesn't need JMF (Java Media Framework)
    • easy to integrate in any application
    • easy to integrate in any web page (as applet).

    For a complete list of its methods and attributes you can check its documentation here.

    Sample code:

    import jaco.mp3.player.MP3Player;
    import java.io.File;
    
    public class Example1 {
      public static void main(String[] args) {
        new MP3Player(new File("test.mp3")).play();
      }
    }
    

    For more details, I created a simple tutorial here that includes a downloadable sourcecode.

提交回复
热议问题