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
Trusted Contributor
Davidf65
Posts: 151
Registered: ‎07-20-2010
My Device: Not Specified
Accepted Solution

Playing audio once its recorded

Can anyone tell me how I should play a recorded audio? I am recording it in the default AMR format. The data is stored in a byte[] array. Now i want to play this data once the recording is finished. Please can someone give me a sample code of how this could be done.

My code is,

player = Manager.createPlayer("capture://audio");

player.realize();

rcControl = (RecordControl) player.getControl("RecordControl");

output = new ByteArrayOutputStream();

rcControl.setRecordStream(output);

rcControl.startRecord();

player.start();

 

Once I hit the stop button, it does the following:

rcControl.commit();

data = outout.toByteArray();

output.close();

player.close();

 

Now, When i hit the play button,

player = Manager.createPlayer(new String(data));  Note: data is a byte array

player. realize();

player.prefetch();

player.start();

 

But when I hit the play button, the player doesnt play this data. Can someone please help me with this. I am really stuck with this. Can someone give me a code for playing this recorded audio? Thanks.

 

Regards,

David

 

 

 

 

 

 

 

 

Please use plain text.
Contributor
sleepymg
Posts: 35
Registered: ‎02-11-2010
My Device: curve 8900

Re: Playing audio once its recorded

I didn't try this but I think it goes something like this:

 

(data is byte[])

 

ByteArrayInputStream bi = new ByteArrayInputStream(data );

player = Manager.createPlayer(bi, "audio/amr");

Please use plain text.
Trusted Contributor
Davidf65
Posts: 151
Registered: ‎07-20-2010
My Device: Not Specified

Re: Playing audio once its recorded

Thank you very much, it worked.

Please use plain text.
New Contributor
mrunal
Posts: 6
Registered: ‎02-20-2012
My Device: Blackberry torch
My Carrier: simulator

Re: Playing audio once its recorded

Hi frnz,

 

I'm also trying to achieve something like this.

Only difference is i want to save the recording to a file.

 

Please tell me what i write on click event of 'Stop & Save' button.

 

Thanks in adavance.

Please use plain text.
Contributor
krishna85
Posts: 36
Registered: ‎10-12-2012
My Device: developer
My Carrier: developer

Re: Playing audio once its recorded

can anyone pls help me with the code for audio recording and playing....

Please use plain text.