01-09-2013 04:23 AM
My application is creating .amr files of 0kb after carrying out voice recording.How can i increase the size of the file.
Solved! Go to Solution.
01-09-2013 04:47 AM
My voice recorder app is creating 0kb files...
@When i call someone a popup comes that a voice recorder(name of my app) is trying to record media.
@But the .amr files it is creating are of 0kb
#is it because of my recorder not working
#is it because of the small duration of the call
What should i do so that it records whatever may be the duration of the call
01-09-2013 06:00 AM
01-09-2013 06:28 AM
Never done this so I can only help by asking the obvious questions like
a) have you confirmed you are writing to the file
b) are you closing the file correctly.
But these are probably redundant.
01-09-2013 07:02 AM
01-09-2013 07:26 AM
I think I am, however i am posting my code if you could help me out.
everytime i call someone.
Hence confirming that recording is taking place
However why the recordings are writing into mu .amr files puzzles me
Thanks in advance
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;
import net.rim.blackberry.api.phone.Phone;
import net.rim.blackberry.api.phone.PhoneCall;
import net.rim.blackberry.api.phone.PhoneListener;
import net.rim.blackberry.api.phone.phonegui.PhoneScreen;
import net.rim.blackberry.api.phone.phonegui.ScreenModel;
import net.rim.device.api.i18n.Locale;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.MainScreen;
/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
public final class RecordScreen extends MainScreen
{
Player player;
RecordControl recorder;
private ByteArrayOutputStream output;
byte[] data;
boolean yes = false;
int st;
/**
* Creates a new RecordScreen object
*/
public RecordScreen()
{
Phone.addPhoneListener(new PhoneListener() {
public void conferenceCallDisconnected(int callId) {
// TODO Auto-generated method stub
}
public void callWaiting(int callid) {
// TODO Auto-generated method stub
}
public void callResumed(int callId) {
// TODO Auto-generated method stub
}
public void callRemoved(int callId) {
// TODO Auto-generated method stub
}
public void callInitiated(int callid) {
PhoneCall phoneCall = Phone.getCall(callid);
if (phoneCall != null)
/* st = Dialog.ask(Dialog.D_YES_NO,
"Are you sure to record this call?");
if (st == Dialog.YES) */
yes = true;
/* else
yes = false; */
// TODO Auto-generated method stub
}
public void callIncoming(int callId) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
// Dialog.ask(Dialog.D_YES_NO, "Are you sure to record this call?");
PhoneCall phoneCall = Phone.getCall(callId);
if (phoneCall != null)
yes=true;
// TODO Auto-generated method stub
/* if (yes) {
try {
recorder.commit();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("====Exception: "+e.getMessage());
}
player.close();
data = output.toByteArray();
saveRecordedFile(data);
} */
}
public void callHeld(int callId) {
// TODO Auto-generated method stub
}
public void callFailed(int callId, int reason) {
// TODO Auto-generated method stub
}
public void callEndedByUser(int callId) {
// TODO Auto-generated method stub
}
public void callDisconnected(int callId) {
// TODO Auto-generated method stub
if (yes)
{
try {
recorder.commit();
data = output.toByteArray();
saveRecordedFile(data);
player.close();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
data = output.toByteArray();
saveRecordedFile(data);
player.close();
}
// player.close();
// data = output.toByteArray();
//saveRecordedFile(data);
/** _rcontrol.commit();
_data = _output.toByteArray();
saveRecordedFile(_data);
_output.close();
_player.close();**/
}
}
public void callDirectConnectDisconnected(int callId) {
// TODO Auto-generated method stub
}
public void callDirectConnectConnected(int callId) {
// TODO Auto-generated method stub
}
public void callConnected(int callId) {
// TODO Auto-generated method s
//@@ScreenModel scr=new ScreenModel(callId);
//set language to english
//@@Locale.setDefault(Locale.get(Locale.LOCALE_en) );
//get Menu
//@@Menu menu=scr.getPhoneScreen(PhoneScreen.PORTRAIT, PhoneScreen.ACTIVECALL).getMenu(0);
/*System.out.println("Menu of BB Dialler - Begin");
for (int i = 0, cnt = menu.getSize(); i < cnt; i++)
System.out.println("Menu of BB Dialler - "
+menu.getItem(i).toString());
System.out.println("Menu of BB Dialler - End"); */
/**for (int i = 0, cnt = menu.getSize(); i < cnt; i++)
if(menu.getItem(i).toString().equalsIgnoreCase("Ac tivate Speakerphone"))
menu.getItem(i).run();
**/
PhoneCall phoneCall = Phone.getCall(callId);
if (phoneCall != null) {
if (yes)
initPlay();
}
if (yes) {
try {
recorder.commit();
} catch (IOException e) {
// TODO Auto-generated catch block
// System.out.println("====Exception: "+e.getMessage());
e.printStackTrace();
}
data = output.toByteArray();
try {
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//player.close();
saveRecordedFile(data);
player.close();
}
}
public void callConferenceCallEstablished(int callId) {
// TODO Auto-generated method stub
}
public void callAnswered(int callId) {
// TODO Auto-generated method stub
// yes = true;
// TODO Auto-generated method stub
}
public void callAdded(int callId) {
// TODO Auto-generated method stub
}
});
// Set the displayed title of the screen
setTitle("");
}
private void initPlay() {
// TODO Auto-generated method stub
try {
player = Manager.createPlayer("capture://audio?encoding=amr ");
player.realize();
recorder = (RecordControl) player.getControl("RecordControl");
output = new ByteArrayOutputStream();
recorder.setRecordStream(output);
recorder.startRecord();
player.start();
} catch (Exception e) {
// TODO: handle exception
//Dialog.alert(e.getMessage() + "");
e.printStackTrace();
}
}
public boolean saveRecordedFile(byte[] data) {
try {
String filePath1 = System.getProperty("fileconn.dir.music");
//WRiting into a file
//String filePath1= "file:///store/home/user/";
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");
e.printStackTrace();
return existed;
}
if (!existed) {
fileName += i + ").amr";
filePath1 += fileName;
break;
}
}//end for
System.out.println(filePath1);
// output---file:///store/home/user/pictures/Photo Editor(10).bmp
System.out.println("");
FileConnection fconn = (FileConnection) Connector.open(filePath1, javax.microedition.io.Connector.READ_WRITE);
if (fconn.exists())
fconn.delete();
fconn.create();
fconn.setHidden(false);
OutputStream outputStream = fconn.openOutputStream();
outputStream.write(data);
outputStream.close();
fconn.close();
return true;
} catch (Exception e) {
//System.out.println("====Exception: "+e.getMessage());
// Dialog.alert("====Exception: "+e.getMessage());
e.printStackTrace();
}
return false;
}
}
01-09-2013 07:41 AM
01-10-2013 02:38 AM
01-10-2013 04:13 AM
01-10-2013 11:52 PM
Yes i know that we cannot record anything during a phonecall.
What i meant to ask was that we do have a mike in a blackberry.So can we record using that mike not necessarily calls but sound recording in general.We can do so in android and other os
Thanks in advance :-)