如何在 Java ME、SE K770i 上使用 RecordControl 录制/捕获音频

发布于 2024-09-02 16:59:39 字数 2303 浏览 1 评论 0原文

我想在 K770i 上的 Java ME 应用程序上录制声音。所以我用了这个:

http:// /java.sun.com/javame/reference/apis/jsr135/javax/microedition/media/control/RecordControl.html

我的代码中的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坏尐絯℡ 2024-09-09 16:59:39

原因可能是它不支持音频捕获。

尝试从索尼手机获取该值。

System.getProperty("supports.audio.capture")

使用附加上述语句的表单编写一个简单的 midlet。像下面这样..

frm.append("支持音频:" + System.getProperty("supports.audio.capture"));

如果这返回错误,那么你就清楚了......
RecordControl 将不起作用。

很少有索尼手机不支持音频捕获......比如索尼 p1i。

希望这有帮助..

The reason might be that it does not support audio capture.

Try to get this value from the Sony phone.

System.getProperty("supports.audio.capture")

Write a simple midlet with a form appending the above statement. like below..

frm.append("Supports Audio:" + System.getProperty("supports.audio.capture"));

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..

锦爱 2024-09-09 16:59:39

好的,正如我所说,我是 java me 新手。所以我需要做的是:

1)添加到 JAD 中的 MIDlet-Permissions 和清单文件到 javax.microedition.media.control.RecordControl

2)在我从其他演示项目使用的 build.bat 中添加 mmapi.jar 的包含,其中RecordControl 位于。

所以我添加了此处显示的最后一行:

set CLDCAPI=%LIB_DIR%\cldcapi10.jar
set MIDPAPI=%LIB_DIR%\midpapi20.jar
set MMAPI=%LIB_DIR%\mmapi.jar

根据此更改更新了另外两行代码:

%JAVAC% -bootclasspath %CLDCAPI%;%MIDPAPI%;%MMAPI% -source 1.3 -target 1.3 -d ..\tmpclasses -classpath ..\tmpclasses %JAVA_FILES%

%PREVERIFY% -classpath %CLDCAPI%;%MIDPAPI%;%MMAPI%;..\tmpclasses -d ..\classes ..\tmpclasses

现在一切都编译良好。这太蹩脚了不是吗?

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:

set CLDCAPI=%LIB_DIR%\cldcapi10.jar
set MIDPAPI=%LIB_DIR%\midpapi20.jar
set MMAPI=%LIB_DIR%\mmapi.jar

And according to this change updated two other lines of code:

%JAVAC% -bootclasspath %CLDCAPI%;%MIDPAPI%;%MMAPI% -source 1.3 -target 1.3 -d ..\tmpclasses -classpath ..\tmpclasses %JAVA_FILES%

%PREVERIFY% -classpath %CLDCAPI%;%MIDPAPI%;%MMAPI%;..\tmpclasses -d ..\classes ..\tmpclasses

And now everything compiles well. It was very lame isn't it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文