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
Contributor
Posts: 22
Registered: ‎08-10-2010
My Device: Not Specified
Accepted Solution

How to record and play Audio

Hi

 

I want a sample code for how to record audio and to play the recorded audio

 

Can anyone help me regarding this??

 

Thanks,

Pavan Kumar

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: How to record and play Audio

Search in the Forums, You will find many Solved Thread like ur thread.

Also look at these Link:

 

http://supportforums.blackberry.com/t5/Java-Development/play-audio-on-click/m-p/434792#M85489

 

http://supportforums.blackberry.com/t5/Java-Development/Playing-audio-within-an-application/m-p/2106...

 

http://supportforums.blackberry.com/t5/Java-Development/playing-simultaneous-waves/m-p/282857#M48040

 

------------------------------------------------------------------------------------

Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.

Contributor
Posts: 22
Registered: ‎08-10-2010
My Device: Not Specified

Re: How to record and play Audio

Hi nitin!!

 

Thanks for reply.

 

I already developed an app to play audio.

Now i'm trying to record audio using headphones and to store that in SDCard .

After storing i want to play the recorded audio.

 

Thanks

Pavan Kumar

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: How to record and play Audio

Read this docs This wil Help u.

 

http://docs.blackberry.com/en/developers/deliverables/11942/CS_recording_audio_from_a_player_740038_...

------------------------------------------------------------------------------------

Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.

Contributor
Posts: 22
Registered: ‎08-10-2010
My Device: Not Specified

Re: How to record and play Audio

I tried the coding but I'm getting 

 

JVMError 104 Uncaught:RunTime Exception.

 

Regular Contributor
Posts: 98
Registered: ‎08-31-2010
My Device: BB-9700

Re: How to record and play Audio

Hi,

 

I already worked on this kind of application. Please provide detail issues what ever you are getting.

 

Thanks

 

Regards

-Abhijit

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: How to record and play Audio

Try to catch the Exception and track that where the Issue is comming.

------------------------------------------------------------------------------------

Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.

Trusted Contributor
Posts: 151
Registered: ‎07-20-2010
My Device: Not Specified

Re: How to record and play Audio

Try this code out, this works for me.

 

For recording the audio. Note that this code saves the audio in the device memory. just change the url to save the code in the sd card.

 

 

try{
            player = Manager.createPlayer("capture://audio?encoding=amr");
            player.realize();
            
            rc = (RecordControl)player.getControl("RecordControl");
            bt = new ByteArrayOutputStream();
            rc.setRecordStream(bt);
            fc = (FileConnection)Connector.open("file:///store/home/user/RecordedFiles/audio1.amr");
            if(!fc.exists()){
                fc.create();
            }
           ot = fc.openDataOutputStream();
            rc.setRecordStream(ot);
            rc.startRecord();
            player.start();   

           
            }catch(Exception e){
                e.printStackTrace();
            }

 

 

 

To stop and play the audio. use this code,

 

try{
            rc.commit();
            
            data = bt.toByteArray();
            bt.close();
            player.close();
          
            
            bi = new ByteArrayInputStream(data);
            
            
            player = Manager.createPlayer(bi,"audio/amr");

 

player.realize();

 

player.start();

}catch(Exception e){
            e.printStackTrace();
        }

 

 

 

 

 

Contributor
Posts: 22
Registered: ‎08-10-2010
My Device: Not Specified

Re: How to record and play Audio

Hi David,

 

Thank You Very much:smileyvery-happy:

 

Its working superbbbbb

Contributor
Posts: 22
Registered: ‎08-10-2010
My Device: Not Specified

Re: How to record and play Audio

Hi David

 

Thank You for your support.I'm having one more doubt.

I created 2 buttons one for record and other for stop and play.

 

The record button is working fine;but the stop and play is having some issue.

when i click the button its not playing the audio.

 

Can u provide some i/p regarding this.

 

Thanks