Hi,
My project consist in a client MIDlet that connects with a server, and a public class written in a separate file that implements a voice recorder.
There is no problem with the MIDlet, but the recorder cannot be compiled, because it has some errors.
First error appears when I declare the public class "grabadora"(means recorder):
"public class" is not abstract and does not override abstract method commandAction(javax.microedition.lcdui.Command,javax.microedition.lcdui.Displayable)in javax.microedition.lcdui.CommandListener
One of my problems is I don't know how to build a project in different files correctly. Where can I find some info about that?
My code is:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Display.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.io.file.*;
import javax.microedition.io.*;
import java.io.*;
public class grabadora implements javax.microedition.lcdui.CommandListener, PlayerListener {
ByteArrayOutputStream outputStream =null;
byte[] byteArray = null;
String locator= "capture://audio";
Player player =null;
Form form;
TextField tb = null;
Command recCommand, stopRecCommand, playCommand,exitCommand;
Display display=null;
RecordControl rc=null;
ChoiceGroup cg;
/** Creates a new instance of HelloMidlet */
public grabadora() { //constructor
cg= new ChoiceGroup ("Record to", ChoiceGroup.EXCLUSIVE);
cg.append("file",null);
cg.append("byteArray", null);
cg.setSelectedIndex(1, true);
form = new Form("Audio Capture");
recCommand = new Command("record", Command.OK, 1);
stopRecCommand = new Command("stop record", Command.OK, 1);
playCommand = new Command("Play", Command.SCREEN, 2);
exitCommand = new Command("Exit", Command.SCREEN, 2);
tb = new TextField("SoundCapture", "info", 256, TextField.UNEDITABLE) ;
form.addCommand(recCommand);
form.addCommand(playCommand);
form.addCommand(exitCommand);
form.setCommandListener(this);
form.append(tb);
form.append(cg);
display.setCurrent(form); //Lo he puesto yo
}
public void commandAction(Command c, Displayable s) {
// Making a boolean vector to get the options from the choicegroup
boolean flags[] = new boolean[2];
flags[0]=false;
flags[1]=false;
cg.getSelectedFlags(flags);
if (c == recCommand) // start the recording
{
System.out.println("recCommand");
tb.setString("Recorder started:");
// Changing the recCommand with the stopCommand
form.removeCommand(recCommand);
form.addCommand(stopRecCommand);
try{
// creating the player from the file url enabling progressive download
player = Manager.createPlayer(locator);
// adding playerListenter
player.addPlayerListener(this);
// allocating the resources from the microphone
player.realize();
// Getting the ReocrdControll so we can record the output from the player
rc = (RecordControl)player.getControl("RecordControl");
}
catch(Exception er){tb.setString(er.toString());}
if(flags[0]) // If we are saving the recorde audio to file
{
try{
// setting the record location to the file
rc.setRecordLocation("file:///c:/other/audio.amr");
// start recording
rc.startRecord();
// start to play the sound from the microphone
player.start();
}catch(Exception t){tb.setString(t.toString());}
}
else // If we are saving to an OutputStream
{
outputStream = null;
outputStream = new ByteArrayOutputStream();
if(rc==null)
System.out.println("rc==null");
// setting the record location to the outputstream
rc.setRecordStream(outputStream);
try{
// start recording
rc.startRecord();
// start to play the sound from the microphone
player.start();
}
catch(Exception e){tb.setString(e.toString());}
}
}
else if (c == stopRecCommand) // Stop the recording
{
System.out.println("StoprecCommand");
// Changing the stopCommand with recCommand
form.removeCommand(stopRecCommand);
form.addCommand(recCommand);
try{
// stop recording
rc.commit();
// and stop the playback from the microphone
player.close();
tb.setString("Recorder to byteArray stopped:");
}
catch(Exception e){tb.setString(e.toString());}
}
else if (c == playCommand) // start the playback of the recorded audio
{
if(flags[0]) // to File
{
System.out.println("play from File");
// creating and starting the playback thread
new PlayerThread("file:///c:/other/audio.amr").start();
}
else // to outputStream
{
System.out.println("play from ByteArrayInputStream");
if(outputStream==null)
return;
// getting the ByteArray from the ByteArrayOutputStream
byteArray = outputStream.toByteArray();
// Creating and starting the playback thread
new PlayerThread(new ByteArrayInputStream(byteArray), "audio/amr" ).start();
}
tb.setString("Playing ");
}
else if (c == exitCommand)
{
}
}
public void playerUpdate(Player player,java.lang.String event,java.lang.Object eventData)
{
System.out.println("playerUpdate event="+event);
}
}
Any suggestions?, thanks a million

Reply With Quote




