`
dicmo
  • 浏览: 68580 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

自制英语默写工具(一)

    博客分类:
  • j2se
阅读更多
下载JMF安装包,把安装后的lib下的jmf.jar和sound.jar放在jre的ext目录下
熟悉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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics