Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
aliajones
Posts: 81
Registered: ‎12-04-2012
My Device: BlackBerry@8520 smartphone(Edge,Wi-fi)
Accepted Solution

How to increase size of file

My application is creating .amr files of 0kb after carrying out voice recording.How can i increase the size of the file.

 

Please use plain text.
Developer
aliajones
Posts: 81
Registered: ‎12-04-2012
My Device: BlackBerry@8520 smartphone(Edge,Wi-fi)

My voice recorder app is creating 0kb files

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

Please use plain text.
Developer
aliajones
Posts: 81
Registered: ‎12-04-2012
My Device: BlackBerry@8520 smartphone(Edge,Wi-fi)

Re: My voice recorder app is creating 0kb files

Could i get some insight
Please use plain text.
Developer
peter_strange
Posts: 19,608
Registered: ‎07-14-2008
My Device: Not Specified

Re: My voice recorder app is creating 0kb files

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. 

Please use plain text.
Developer
simon_hain
Posts: 16,201
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: My voice recorder app is creating 0kb files

you cannot record audio during a call
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
aliajones
Posts: 81
Registered: ‎12-04-2012
My Device: BlackBerry@8520 smartphone(Edge,Wi-fi)

Re: My voice recorder app is creating 0kb files

I think I am, however i am posting my code if you could help me out.

  • this is what actually the problem is that it is not writing into my .amr file though it is creating them

        everytime i call someone.

  • Moreover it is also telling me that "myappname" is trying to record media.

         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("Activate 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;
    }
    
}

 

Please use plain text.
Developer
simon_hain
Posts: 16,201
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: My voice recorder app is creating 0kb files

http://supportforums.blackberry.com/t5/Java-Development/Voice-Call-Recording-Still-not-possible/m-p/...

Mark Sohm writes that you cannot record a call, i would be very surprised if you could do it anyhow.

There are several other issues with your code, for example a phone listener should not block in its listener methods.

in any case, you can add some debug statements to your saveRecordedFile method to check the size and content of the byte array you get before you investigate into the wrong direction.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
aliajones
Posts: 81
Registered: ‎12-04-2012
My Device: BlackBerry@8520 smartphone(Edge,Wi-fi)

Re: My voice recorder app is creating 0kb files

Thanks For the guidance,,,but is simple mike recording over the phone also not possible.
Thanks :-)
Please use plain text.
Developer
simon_hain
Posts: 16,201
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: My voice recorder app is creating 0kb files

as far as i know you cannot record anything during a phone call, but feel free to try that out yourself.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
aliajones
Posts: 81
Registered: ‎12-04-2012
My Device: BlackBerry@8520 smartphone(Edge,Wi-fi)

Re: My voice recorder app is creating 0kb files

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 :-)

 

Please use plain text.