Hi Leute..
Bin immer noch an meinem einfachen Diktiergerät dran.. nun habe ich es ein wenig erweitert..
und es kommt folgender Fehler wenn ich es im Simulator von Sony probiere:
/*Fehler:
Running with storage root temp.SonyEricsson_W950_Emu53
Running with locale: German_Germany.1252
Warning: To avoid potential deadlock, operations that may block, such as
networking, should be performed in a different thread than the
commandAction() handler.
*/
In der Simulation bzw. auf dem Handy gehe ich so vor:
1. "Aufnahme" anklicken
2. Dateinamen in eingeben und mit OK bestätigen.
3. Im Simulator stellt er jetzt noch die Frage ob er schreiben darf, aber die kann ich schon nicht mehr beantworten weil die Simu abgebrochen wurde mit dem oben genannten Fehler
Auf dem Handy kann ich ich noch die Schreibrechte abfragen und dann stürzt das Programm ab
Wo liegt mein Fehler und wie kann ich ihn korriegieren??
Danke
Thomas
Bin immer noch an meinem einfachen Diktiergerät dran.. nun habe ich es ein wenig erweitert..
und es kommt folgender Fehler wenn ich es im Simulator von Sony probiere:
/*Fehler:
Running with storage root temp.SonyEricsson_W950_Emu53
Running with locale: German_Germany.1252
Warning: To avoid potential deadlock, operations that may block, such as
networking, should be performed in a different thread than the
commandAction() handler.
*/
In der Simulation bzw. auf dem Handy gehe ich so vor:
1. "Aufnahme" anklicken
2. Dateinamen in eingeben und mit OK bestätigen.
3. Im Simulator stellt er jetzt noch die Frage ob er schreiben darf, aber die kann ich schon nicht mehr beantworten weil die Simu abgebrochen wurde mit dem oben genannten Fehler
Auf dem Handy kann ich ich noch die Schreibrechte abfragen und dann stürzt das Programm ab
Wo liegt mein Fehler und wie kann ich ihn korriegieren??
Danke
Thomas
Java:
package RECORDER;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class Main extends MIDlet {
MainForm mainform;
Display display;
RecordForm recordform;
public Main() {
mainform = new MainForm("Media");
recordform = new RecordForm("Recorder");
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
display.setCurrent(mainform);
}
private class MainForm extends Form implements CommandListener{
Command EXIT, PLAYER, RECORDER;
public MainForm(String title){
super(title);
EXIT = new Command("Exit", Command.EXIT, 1);
PLAYER = new Command("Player", Command.SCREEN, 1);
RECORDER = new Command("Aufnahme", Command.SCREEN, 1);
this.addCommand(RECORDER);
this.addCommand(EXIT);
//this.addCommand(PLAYER);
this.setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if(c==EXIT){
try {
destroyApp(false);
} catch (MIDletStateChangeException e) {
e.printStackTrace();
}
}
if(c==PLAYER){
//display.setCurrent(new PlayerForm("MediaPlayer"));
}
if(c==RECORDER){
display.setCurrent(recordform);
}
}
}
private class RecordForm extends Form implements CommandListener{
private TextField textfield;
private Command BACK, OK, REC_START, REC_STOP;
private String path="";
private boolean breaker;
private Player captureplayer;
private RecordControl rc;
private ByteArrayOutputStream output = new ByteArrayOutputStream();
private DataOutputStream dos;
public RecordForm(String title){
super(title);
BACK = new Command("Zurück", Command.CANCEL, 1);
OK = new Command("Ok", Command.OK, 1);
textfield = new TextField("Dateinamen eingeben:", "", 16, TextField.ANY);
this.addCommand(OK);
this.addCommand(BACK);
this.append(textfield);
this.setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if(c==BACK){
display.setCurrent(mainform);
}
if(c==OK){
path = "file:///e:/"+textfield.getString()+".amr";
try {
FileConnection fc = (FileConnection)Connector.open(path,Connector.READ_WRITE);
if(!fc.exists()){
fc.create();
}
fc.close();
} catch (IOException e) {
e.printStackTrace();
}
this.deleteAll();
this.append("Ziel-Datei:\n"+path);
this.removeCommand(BACK);
this.removeCommand(OK);
this.addCommand(REC_START);
}
if(c==REC_START){
this.removeCommand(REC_START);
this.addCommand(REC_STOP);
breaker=true;
this.append("Aufnahme gestartet");
this.record();
}
if(c==REC_STOP){
breaker=false;
this.append("Aufnahme beendet und in Datei "+path+"abgespeichert!");
this.removeCommand(REC_STOP);
this.addCommand(BACK);
}
}
private void record(){
Thread record = new Thread(){
public void run(){
try {
captureplayer = Manager.createPlayer("capture://audio?encoding=amr");
captureplayer.realize();
rc = (RecordControl)captureplayer.getControl("RecordControl");
rc.setRecordStream(output);
rc.startRecord();
captureplayer.start();
while(breaker){};
rc.stopRecord();
rc.commit();
captureplayer.stop();
captureplayer.close();
FileConnection fc2 = (FileConnection)Connector.open(path,Connector.READ_WRITE);
dos = fc2.openDataOutputStream();
dos.write(output.toByteArray());
dos.close();
output.close();
} catch (IOException e) {
e.printStackTrace();
} catch (MediaException e) {
e.printStackTrace();
}
}
};
record.start();
}
}
}