views:

278

answers:

2

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?

+2  A: 

Hi,

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

Vijay C
It returns info that it is suported on my mobile. What to do now?
tomaszs
A: 

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?

tomaszs