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
Posts: 229
Registered: ‎11-21-2009
My Device: Not Specified

Really need some help...Record Audio...should be so simple...

I've spent so much time on this and investigated every angle...I took the example right out (and others) right out of the doc and postings...this code is about my 5th variation...

 

No matter what, size is always either 1024 (which I think is really just the default ByteArray allocation block) or 0 - it's almost like the device is buffering data, blocked (I'm not tying up Event Thread - does it need EventThread  or lock)...makes no sense.

 

Video Notes Recorder works fine, so - no issues with the device...it's a 8530, real device, V5 OS...

 

I execute this from Event Dispatch Thread (via Menu pick):

 

doRecordThread();

 

 

I have this (I run with/without thread - makes no difference really)

 

	public static String theResult=null;
	
	public static void doRecordThread()
	{
	new Thread() {
		public void run()
		{
		theResult=doRecord();
		Thread dThread=new Thread() {
			public void run()
			{
			net.rim.device.api.ui.component.Dialog.inform(theResult);
			}
		};
		net.rim.device.api.ui.UiApplication.getUiApplication().invokeLater(dThread);
		}
	}.start();
	}
	
	public static String doRecord() 
	{
	try {
        // Create a Player that captures live audio.
        Player p = Manager.createPlayer("capture://audio");
        p.realize();
       // Get the RecordControl, set the record stream,
       // start the Player and record for 5 seconds.
        RecordControl rc = (RecordControl)p.getControl("RecordControl");
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        rc.setRecordStream(output);
        rc.startRecord();
        p.start();
        Thread.currentThread().sleep(30000);
        rc.commit();
        p.close();
	    return "Size is: "+output.size();		
	}
	catch(Exception e) {
		  return "Error is "+e.toString();
	}
	}

 

Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: Really need some help...Record Audio...should be so simple...

try using "capture://audio?encoding=gsm"

 

Is your device a CDMA device?

Developer
Posts: 229
Registered: ‎11-21-2009
My Device: Not Specified

Re: Really need some help...Record Audio...should be so simple...

Aviator -

 

Thanks...

 

But this does not work either...I get 0 size...

 

I cannot seem to find what is wrong here...and I see tons of example code - pretty

 

much identical to mine....

 

I don't get it....

 

The phone is a 8530 running V5 s/w....

 

Developer
Posts: 157
Registered: ‎05-10-2009
My Device: Not Specified

Re: Really need some help...Record Audio...should be so simple...

 

Maybe try this to force AMR format (though I believe that amr is the default and this probably won't help)

 

Manager.createPlayer("capture://audio?encoding=audio/amr");

Developer
Posts: 229
Registered: ‎11-21-2009
My Device: Not Specified

Re: Really need some help...Record Audio...should be so simple...

macdan,

 

Thanks for your suggestion, but I have already tried it...

 

But - if anyone is "bored" and "curious" - perhaps you can cut/paste my code and verify you get same results?

Developer
Posts: 484
Registered: ‎07-17-2008
My Device: Not Specified

Re: Really need some help...Record Audio...should be so simple...

How about calling doRecord without all the threading stuff just to see if it works?

Developer
Posts: 229
Registered: ‎11-21-2009
My Device: Not Specified

Re: Really need some help...Record Audio...should be so simple...

Yea...it's a mess...

 

Tried that too...

 

I've tried about every variation of this...does not work on my phone...

Developer
Posts: 157
Registered: ‎05-10-2009
My Device: Not Specified

Re: Really need some help...Record Audio...should be so simple...

I may sound odd, but I had a similar problem and thought it was all about event thread vs. other thread.  I separated the start and stop recording code into separate methods and invoked them directly from listeners keyed to the 'send' and 'end' button respectively.  (removing the need for the thread.sleep) and did everything in the event thread.  That fixed my problem but I've no idea why.   If the same thing is done from a buttonfield event listener, it did not work.  Based on this, I posted a similar question as yours to the forum but came up empty.

 

 

Developer
Posts: 229
Registered: ‎11-21-2009
My Device: Not Specified

Re: Really need some help...Record Audio...should be so simple...

Well,

 

I am desparate...

 

And will take your advice...

 

I do not have nearly the same types of issues on the Android side...

 

This is something so basic and there is code posted everywhere, in fact I took my first version right off a knowledge article - it really just blows me away that this very simple function does not work and as far as I can tell via search - I'm the only guy on the planet (other than you now) who can't make it work.

 

But - I am going to try your suggestion...thanks for helping me...I have burned way too much time on this...

 

The funny thing is the stuff I thought would not work - does work, and the stuff I think is a peice of cake - does not work...

Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: Really need some help...Record Audio...should be so simple...

Another thing. If you are running this on an actual device, make sure you set the app property to allow record.