最近在学习有关jmf的知识,在用jmf捕获声音时出现的问题,代码如下:

 

 
  
  1. package jmf; 
  2.  
  3. import java.awt.Component; 
  4. import java.util.Vector; 
  5.  
  6. import javax.media.*; 
  7. import javax.media.format.AudioFormat; 
  8. import javax.swing.JFrame; 
  9. import javax.swing.JPanel; 
  10.  
  11. public class CaptureAudio2 extends JFrame implements ControllerListener{ 
  12.     Player player = null
  13.     MediaLocator locator = null
  14.     CaptureDeviceInfo captureInfo ; 
  15.     private JPanel panel; 
  16.     Component com1; 
  17.     Component com2; 
  18.         
  19.     public CaptureAudio2()  
  20.     { 
  21.         Vector<CaptureDeviceInfo>  deviceList = CaptureDeviceManager.getDeviceList(new AudioFormat(AudioFormat.LINEAR,44100,16,2)); 
  22.         captureInfo = (CaptureDeviceInfo)deviceList.get(0); 
  23.         locator = captureInfo.getLocator(); 
  24.     } 
  25.     public void createComponent() { 
  26.         setTitle("视频信号"); 
  27.         // addWindowListener(new WinClose()); 
  28.         //setBounds(100, 100, 400, 400); 
  29.         panel = new JPanel(); 
  30.         if ((com1 = player.getVisualComponent()) != null) { 
  31.             panel.add(com1); 
  32.         } 
  33.         if((com2=player.getControlPanelComponent())!=null) 
  34.             panel.add(com2); 
  35.         add(panel); 
  36.         pack(); 
  37.         setVisible(true); 
  38.     } 
  39.     public void play()  
  40.     { 
  41.         try { 
  42.             player = Manager.createPlayer(locator); 
  43.             player.addControllerListener(this); 
  44.             player.realize(); 
  45.              
  46.         } catch (Exception e) { 
  47.             // TODO: handle exception 
  48.             e.printStackTrace(); 
  49.         } 
  50.     } 
  51.       
  52.       
  53.     public void controllerUpdate(ControllerEvent e)  
  54.     { 
  55.            if(e instanceof RealizeCompleteEvent) 
  56.            {     
  57.                player.prefetch(); 
  58.                createComponent();  
  59.            } 
  60.            if(e instanceof PrefetchCompleteEvent) 
  61.                player.start(); 
  62.     } 
  63.       
  64.     public static void main(String[] args)  
  65.     { 
  66.         CaptureAudio2 audio = new CaptureAudio2(); 
  67.         audio.play(); 
  68.     } 

运行后的视图如下:

 

 

不过之前我用jmf捕获音频并保存到本地是可以捕获到的,但我是用手机开非常大的声音才勉强可以捕获到,现在我是用MP3的耳塞在做声源,用电脑接收后直接播放出来,结果就是没声音。但我看哪个Media Properties 和 PlugIn Viewer 貌似又是启动的捕获过程。不知道为什么,问同学也没有人知道,老师也不是很懂这个......只能来51cto求助了..