下载JMF安装包,把安装后的lib下的jmf.jar和sound.jar放在jre的ext目录下
熟悉JMF
重要代码:
编译后运行 java SimpleAudioPlayer xxxx.mp3
熟悉JMF
重要代码:
import javax.media.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;
public class SimpleAudioPlayer {
private Player audioPlayer = null;
public SimpleAudioPlayer(URL url) throws IOException,//通过URL地址播放
NoPlayerException,
CannotRealizeException {
audioPlayer = Manager.createRealizedPlayer(url);
}
public SimpleAudioPlayer(File file) throws IOException,//通过本地文件播放
NoPlayerException,
CannotRealizeException {
this(file.toURL());
}
public void play() {
audioPlayer.start();
}
public void stop() {
audioPlayer.stop();
audioPlayer.close();
}
public static void main (String [] args) throws Exception {
File audioFile = new File(args[0]); //命令行下获取播放文件名
SimpleAudioPlayer player = new SimpleAudioPlayer(audioFile);
player.play();
// player.stop();
}
}
编译后运行 java SimpleAudioPlayer xxxx.mp3