首页 新闻 会员 周边

有关JMF捕获音频的小问题

0
[已关闭问题] 关闭于 2012-06-06 23:53

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

 1 package myJMF;
 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 }
69 }

 


运行后的视图如下:

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

征和的主页 征和 | 菜鸟二级 | 园豆:202
提问于:2012-05-24 17:03
< >
分享
所有回答(1)
0

你好,我是JAVA 初学者。刚开始研究JMF音频截取。。但是用eclipse运行你的代码。 运行不了。。JMF包都加载好了。。

出现以下问题:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
at java.util.Vector.get(Unknown Source)
at CaptureAudio2.<init>(CaptureAudio2.java:20)
at CaptureAudio2.main(CaptureAudio2.java:64

不知以上是什么原因。谢谢解答

strangerwww | 园豆:202 (菜鸟二级) | 2013-06-28 04:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册