1. First introduce Jlayer.jar
<!--https://mvnrepository.com/artifact/javazoom/jlayer<dependency> < groupid>javazoom</groupid> <artifactId>jlayer</artifactId> <version>1.0.1 </version></dependency>
2. The code is as follows
PackageCom.xinfushe.taskbot.util;ImportJava.io.BufferedInputStream;ImportJava.io.FileInputStream;ImportJavazoom.jl.player.Player;/*** MP3 Player * *@authorLIFQ * * April 7, 2017 pm 5:29:57*/ Public classMp3player {PrivateString filename; Privateplayer player; Publicmp3player (String filename) { This. FileName =filename; } Public voidPlay () {Try{Bufferedinputstream buffer=NewBufferedinputstream (Newfileinputstream (filename)); Player=NewPlayer (buffer); Player.play (); } Catch(Exception e) {System.out.println (e); } } Public Static voidMain (string[] args) {mp3player mp3=NewMp3player ("D:/2.mp3"); Mp3.play (); }}
Java Implementation play MP3 function