1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;
public class PlayerMIDlet extends MIDlet{
private Form form;
private Player player;
private RecordControl recordControl;
private ByteArrayOutputStream out;
public PlayerMIDlet(){
form = new Form("Recording");
showVoiceRecorder();
}
public void startApp(){
Display.getDisplay(this).setCurrent(form);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
private void showVoiceRecorder(){
Thread t = new Thread(){
public void run(){
try{
player = Manager.createPlayer("capture://audio");
player.realize();
recordControl = (RecordControl) player.getControl("RecordControl");
out = new ByteArrayOutputStream();
recordControl.setRecordStream(out);
recordControl.startRecord();
player.start();
Thread.sleep(5000);
player.stop();
recordControl.stopRecord();
recordControl.commit();
player.close();
form.append("End");
}
catch (InterruptedException ex){
ex.printStackTrace();
form.append(ex.getMessage());
}
catch (IOException ex){
ex.printStackTrace();
form.append(ex.getMessage());
}
catch (MediaException ex){
ex.printStackTrace();
form.append(ex.getMessage());
}
}
};
t.start();
}
} |
Partager