01-14-2013 07:02 AM
I am successfully able to record using the mike of the blackberry through code.However the files that are being made which are .amr files.after a recording of say 1min a file of 132kb is made.which is quite huge in j2me standards
Could dere be sum other encryption type like .amr which would make lighter files.What can i do so dat a large no. of small files are made instead of a single heavy file.
private static final long mtime = 100000;//records for 1min
RecordControl rc;
byte[] data;
public void run()
{
// TODO Auto-generated method stub
try
{ Player p = Manager.createPlayer("capture://audio?encoding=amr "); // Player p set to capture audio here
p.realize();
rc = (RecordControl)p.getControl("RecordControl");
ByteArrayOutputStream os = new ByteArrayOutputStream();
rc.setRecordStream(os);
/**FileConnection fc = (FileConnection)Connector.open("file:///store/home /user/RecordedFiles/audio1.amr");
//if(!fc.exists())
{
fc.create();
}
DataOutputStream ot= fc.openDataOutputStream();**/
//rc.setRecordStream(ot);
rc.startRecord();//starts the recording
p.start();
Thread.sleep(MikeApp.mtime);
rc.commit();
p.close();
data = os.toByteArray();
saveRecordedFile(data);
if (p != null)
{
p.stop();
p.close();
p = null;
}
}
catch (IOException e)
{
e.printStackTrace();
}
catch (MediaException e)
{
e.printStackTrace();
}
catch (InterruptedException e)
{
e. printStackTrace();
}
return;
}
public static boolean saveRecordedFile(byte[] data)
{
try {
String filePath1 = System.getProperty("fileconn.dir.music");
String fileName = "Call Recorder(";
boolean existed = true;
for (int i = 0; i < Integer.MAX_VALUE; i++)
{
try {
FileConnection fc = (FileConnection) Connector.open(filePath1 + fileName + i + ").amr");
if (!fc.exists())
{
existed = false;
}
fc.close();
}
catch (IOException e)
{
// Dialog.alert("unable to save");
return existed;
}
if (!existed)
{
fileName += i + ").amr";
filePath1 += fileName;
break;
}
}
System.out.println(filePath1);
System.out.println("");
FileConnection fconn = (FileConnection) javax.microedition.io.Connector .open(filePath1, javax.microedition.io.Connector.READ_WRITE);
if (fconn.exists())
fconn.delete();
fconn.create();
OutputStream outputStream = fconn.openOutputStream();
outputStream.write(data);
outputStream.close();
fconn.close();
return true;
}
catch (Exception e)
{
e.printStackTrace();
}
Solved! Go to Solution.
01-16-2013 01:35 AM
01-16-2013 07:05 AM