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: 13
Registered: ‎10-06-2011
My Device: BlackBerry Bold
My Carrier: Telefonica

Recording auido

I'm trying to implement the audio recorder from this article:

http://docs.blackberry.com/en/developers/deliverables/17968/Record_audio_in_a_BB_device_app_1222372_...

 

In my application I'm calling the start to this thread when a user presses a button, and stop it when the user press it again, I created a sort of button with state to use the same for start and stop, the states works fine, I know 'cause of some dialogs I put in it, however my thread is not being executed, also know it 'cause some dialogs in the run and stop methods,

 

is there any special consideration I should take when starting the thread from a FieldChangeListener method?

 

here's the code where I try to start the thread:

 

StateButtonField swipeBtn	= new StateButtonField( "Swipe", "Done", FIELD_HCENTER | ButtonField.CONSUME_CLICK );
        swipeBtn.setChangeListener( new FieldChangeListener() {
            public void fieldChanged( Field field, int context ) {
                StateButtonField btn        = (StateButtonField) field;
                
                if ( btn.clicked ) {
                    // Start recording
                    Dialog.alert( "Button pressed" );
                    _recorder.start();
                } else {);
                    Dialog.alert( "Stoping" );
                    _result = _recorder.stop();
                }
            }
        });
        
this.add( label );
this.add( swipeBtn );

 and here's the code for my run and stop methods in the thread

 

/**
     * Method used to start the thread and record
     * 
     * @return	void
     * @access	public
     */
    public void run() {
        Dialog.alert( "starting" );
        
        try {
            this._player	= Manager.createPlayer( "capture://audio" );
            this._player.addPlayerListener( this );
            
            _player.realize();
            this._rcontrol	= (RecordControl) _player.getControl( "RecordControl" );
            this._output	= new ByteArrayOutputStream();
            this._rcontrol.setRecordStream( this._output );
            
            // Start recording the signal from the microphone
            this._rcontrol.startRecord();
            this._player.start();
        } catch( final Exception e ) {
            Dialog.alert( e.toString() );
        }
    }
    
    /**
     * Method used to stop recording and write the data to decode the signal
     * 
     * @return	byte[]		The byte array containing the recorded stream
     * @access	public
     */
    public byte[] stop() {
        try {
            // Stop the recording and get the obtained data
            this._rcontrol.commit();
            this._data	= this._output.toByteArray();
            Dialog.alert( "stopped" );
            
            // Close the stream and the player used to record
            this._output.close();
            this._player.close();
            
            return this._data;
        } catch( Exception e ) {
            Dialog.alert( e.toString() );
            
            return this._data;
        }
    }

 Any help is appreciated, thanks in advance

 

Chuck

Contributor
Posts: 13
Registered: ‎10-06-2011
My Device: BlackBerry Bold
My Carrier: Telefonica

Re: Recording auido

Why is it that all threads in this forum are answered but mine =O

 

I'm shocked, it's like the fifth time this happens