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)
My Carrier: vodafone
Accepted Solution

How to decrease size of audio file

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();
    }
   
Please use plain text.
Developer
aliajones
Posts: 81
Registered: ‎12-04-2012
My Device: BlackBerry@8520 smartphone(Edge,Wi-fi)
My Carrier: vodafone

Re: How to decrease size of audio file

I am currently able to record using the microphone and a .amr file is created whose recording time is as much as much is specified in sleep.
However what i want is that a new file is created each time after recording for a certain period of time.
Say record1.amr records for 1min.and as soon as the min is over a new file is created.
this happens till the time we uninstall the app .
could i get some insight
Please use plain text.
Developer
aliajones
Posts: 81
Registered: ‎12-04-2012
My Device: BlackBerry@8520 smartphone(Edge,Wi-fi)
My Carrier: vodafone

Re: How to decrease size of audio file

this problem has been solved.
thanks people for the quick responses
Please use plain text.