本文是作者毕设所设计到的技术,因为已经做完,所以想将一些技术总结与大家分享一下,希望能和大家有交流的机会.
捕获音频设备的核心代码先写如下:
AudioFormat audioFormat ;
Vector audioDeviceList ;
CpatureDeviceInfo cdi = null;
MediaLocator mediaLocator ;
MediaPlayer player ;
audioFormat = new AudioFormat(AudioFormat.LINEAR);
audioDeviceList = CpatureDeviceManager.getDeviceList(audioFormat); i
f(audioDeviceList == null || audioDeviceList.size() < 1 ) {
System.out.println("未捕获到音频设备,请检查设备是否正确连接"); }
else {
cdi = (CaptureDeviceInof)audioDeviceList.elementAt(0);
mediaLocator = cdi.getLocator(); player = new MediaPlayer();
player.setMediaLocator(mediaLocator);
player.addControllerListener(this);
player.realize(); }
public void controllerUpdate(ControllerEvent e) {
if(e instanceof RealizeCompleteEvent) {
player.prefetch(); }
if(e instanceof PrefetchCompleteEvent) {
player.start(); }
if(e instanceof ControllerCloseEvent) {
player.stop();
player.close(); }
} 以上代码就可以实现捕获到本机的麦克并本机播放,自己就可以通过麦克听到自己的声音了,更多的基础知识请参考JMF基础教程