本文為大家分享了用java來播放mp3的具體代碼,使用jl1.0.1.jar,供大家參考,具體內容如下
代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
import java.io.bufferedinputstream; import java.io.fileinputstream; import javazoom.jl.player.player; /** * @author brandon b. lin * 2013-1-25 */ public class mp3player { public mp3player(string filename) { this .filename = filename; } public void play() { try { bufferedinputstream buffer = new bufferedinputstream( new fileinputstream(filename)); player = new player(buffer); player.play(); } catch (exception e) { system.out.println(e); } } public static void main(string[] args) { mp3player mp3 = new mp3player( "陳瑞 - 白狐.mp3" ); mp3.play(); } private string filename; private player player; } |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://www.oschina.net/code/snippet_937173_17692