Hi
When I change my emulator to SUN WTK, the audio is ok.Here is the codes,hoping it helpful for others....
Code:
package record.audio;
import javax.microedition.midlet.MIDlet;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.*;
import javax.microedition.io.file.*;
import javax.microedition.io.*;
public class RecordAudio extends MIDlet {
Player player1, player2;
ByteArrayOutputStream bos;
ByteArrayInputStream bis;
RecordControl rc;
FileConnection fconn;
DataOutputStream dos;
DataInputStream dis;
public RecordAudio() {
}
protected void destroyApp(boolean arg0) {
}
protected void pauseApp() {
}
protected void startApp() {
try{
try {
fconn = (FileConnection)Connector.open("file:///root1/newfile.wav");
// If no exception is thrown, then the URI is valid, but the file may or may not exist.
if (!fconn.exists())
{
fconn.create(); // create the file if it doesn't exist
System.out.println("FILE Exist");
}
//fconn.close();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
try{
player1 = Manager.createPlayer("capture://audio");
}catch(Exception e){
System.out.println("creat error");
e.printStackTrace();
}
System.out.println("After CREAT");
player1.realize();
try{
rc = (RecordControl) player1.getControl("RecordControl");
}catch(Exception e){
System.out.println("RecordControl error");
e.printStackTrace();
}
bos = new ByteArrayOutputStream();
try{
rc.setRecordStream(bos);
}catch(Exception e){
System.out.println("rc.setRecordStream(bos) error");
}
player1.prefetch();
try {
rc.startRecord();
} catch (Exception e) {
e.getMessage();
}
player1.start();
Thread.sleep(10000);
try {
rc.commit();
} catch (Exception e) {
e.getMessage();
}
player1.close();
System.out.println("After CLOSE");
try{
dos = fconn.openDataOutputStream();
dos.write(bos.toByteArray());
dos.flush();
dos.close();
fconn.close();
}catch(Exception e){
e.printStackTrace();
System.out.println("dos error");
}
System.out.println("After Save Before Open");
try{
fconn = (FileConnection)Connector.open("file:///root1/newfile.wav");
if(fconn.exists())
System.out.println("Open");
dis = fconn.openDataInputStream();
}catch(Exception e){
e.printStackTrace();
}
try{
player2 = Manager.createPlayer(dis, "audio/x-wav");
}catch(Exception e){
e.printStackTrace();
}
System.out.println("After CREAT player2");
try{
player2.realize();
}catch(Exception e){
System.out.println("******");
e.printStackTrace();
e.getMessage();
System.out.println("*******");
}
try{
player2.prefetch();
player2.start();
}catch(Exception e){
e.printStackTrace();
}
System.out.println("The end!!");
}catch(Exception e){
e.printStackTrace();
}
}
}