Playing .mp3 and .wav in Java?

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

    The easiest way I found was to download the JLayer jar file from http://www.javazoom.net/javalayer/sources.html and to add it to the Jar library http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29

    Here is the code for the class

    public class SimplePlayer {
    
        public SimplePlayer(){
    
            try{
    
                 FileInputStream fis = new FileInputStream("File location.");
                 Player playMP3 = new Player(fis);
    
                 playMP3.play();
    
            }  catch(Exception e){
                 System.out.println(e);
               }
        } 
    }
    

    and here are the imports

    import javazoom.jl.player.*;
    import java.io.FileInputStream;
    

提交回复
热议问题