如何在 Java ME、SE K770i 上使用 RecordControl 录制/捕获音频
我想在 K770i 上的 Java ME 应用程序上录制声音。所以我用了这个:
我的代码中的 RecordControl 示例。它是这样的:
import java.util.Vector;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.midlet.MIDlet;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
(...)
try {
// Create a Player that captures live audio.
Player p = Manager.createPlayer("capture://audio");
p.realize();
// Get the RecordControl, set the record stream,
// start the Player and record for 5 seconds.
RecordControl rc = (RecordControl)p.getControl("RecordControl");
ByteArrayOutputStream output = new ByteArrayOutputStream();
rc.setRecordStream(output);
rc.startRecord();
p.start();
Thread.currentThread().sleep(5000);
rc.commit();
p.close();
} catch (IOException ioe) {
} catch (MediaException me) {
} catch (InterruptedException ie) { }
但不幸的是,当我尝试构建它时,它告诉我:
*** Creating directories ***
*** Compiling source files ***
..\src\example\audiodemo\AudioPlayer.java:121: cannot find symbol
symbol : class RecordControl
location: class example.audiodemo.AudioPlayer
RecordControl rc = (RecordControl)p.getControl("RecordControl");
^
..\src\example\audiodemo\AudioPlayer.java:121: cannot find symbol
symbol : class RecordControl
location: class example.audiodemo.AudioPlayer
RecordControl rc = (RecordControl)p.getControl("RecordControl");
^
2 errors
所以我的问题是:为什么没有 RecordControl 类,如果在文档中写这个类应该在那里。或者还有其他方法可以在索尼爱立信的 Java ME 中从麦克风录制/捕获音频吗?
你如何录制声音?
I want to record sound on my Java ME App on K770i. So I used this:
http://java.sun.com/javame/reference/apis/jsr135/javax/microedition/media/control/RecordControl.html
example of RecordControl in my code. It goes like this:
import java.util.Vector;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.midlet.MIDlet;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
(...)
try {
// Create a Player that captures live audio.
Player p = Manager.createPlayer("capture://audio");
p.realize();
// Get the RecordControl, set the record stream,
// start the Player and record for 5 seconds.
RecordControl rc = (RecordControl)p.getControl("RecordControl");
ByteArrayOutputStream output = new ByteArrayOutputStream();
rc.setRecordStream(output);
rc.startRecord();
p.start();
Thread.currentThread().sleep(5000);
rc.commit();
p.close();
} catch (IOException ioe) {
} catch (MediaException me) {
} catch (InterruptedException ie) { }
But unfortunately when I try to build it, it tells me:
*** Creating directories ***
*** Compiling source files ***
..\src\example\audiodemo\AudioPlayer.java:121: cannot find symbol
symbol : class RecordControl
location: class example.audiodemo.AudioPlayer
RecordControl rc = (RecordControl)p.getControl("RecordControl");
^
..\src\example\audiodemo\AudioPlayer.java:121: cannot find symbol
symbol : class RecordControl
location: class example.audiodemo.AudioPlayer
RecordControl rc = (RecordControl)p.getControl("RecordControl");
^
2 errors
So my question is: why there is no RecordControl class if in documentations it is written this class should be there. Or is there other method to record / capture audio from microfone in Java ME of Sony Ericsson?
How do you record sound?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
原因可能是它不支持音频捕获。
尝试从索尼手机获取该值。
使用附加上述语句的表单编写一个简单的 midlet。像下面这样..
如果这返回错误,那么你就清楚了......
RecordControl 将不起作用。
很少有索尼手机不支持音频捕获......比如索尼 p1i。
希望这有帮助..
The reason might be that it does not support audio capture.
Try to get this value from the Sony phone.
Write a simple midlet with a form appending the above statement. like below..
If this returns the false, then you are clear...
The RecordControl wont work.
Few Sony phones dont support audio capture..like Sony p1i.
Hope this helps..
好的,正如我所说,我是 java me 新手。所以我需要做的是:
1)添加到 JAD 中的 MIDlet-Permissions 和清单文件到 javax.microedition.media.control.RecordControl
2)在我从其他演示项目使用的 build.bat 中添加 mmapi.jar 的包含,其中RecordControl 位于。
所以我添加了此处显示的最后一行:
根据此更改更新了另外两行代码:
现在一切都编译良好。这太蹩脚了不是吗?
OK, so as i said I am java me newbie. So what I needed to do:
1) Added to MIDlet-Permissions in JAD and Manifest file to javax.microedition.media.control.RecordControl
2) In build.bat that I used from other demo project add inclusion of mmapi.jar, where the RecordControl is located in.
So i've added one last line shown here:
And according to this change updated two other lines of code:
And now everything compiles well. It was very lame isn't it?