BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 01-14-2010, 05:10 PM   #1 (permalink)
New Member
 
Join Date: Jul 2009
Model: 9530
PIN: N/A
Carrier: Nokia
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Voice Recording issues in Blackberry Storm.

Please Login to Remove!

Hello All

I am facing recording issues in Blackberry storm series. The code is working fine in other models. But in 9500 series I am getting the problem. When I tested the application, I am always getting zero bytes. Also most of the times, Application is getting hanged because of Player component.

Below is the code I am using for this
Code:
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;


public class VoiceRecorderComponent extends Thread  {
	private Player _player;
	private RecordControl _rcontrol;
	private ByteArrayOutputStream _output;
	private byte _data[];
	private int choice=-1;
	public static final long MAX_RECORDING_TIME = 30000;
	public static final int START_RECORDER = 0;
	public static final int PAUSE_RECORDER = 1;
	public static final int DESTROY_RECORDER = 2;
	public static final int RESUME_RECORDER = 3;
	public VoiceRecorderComponent() {
		_player=null;
		_rcontrol=null;
		_output=null;
		initRecorder();
	}



	public void setCommand(int choice) {
		this.choice = choice;
		switch (choice) {
		case START_RECORDER:
			
			start();
			
			break;
		case PAUSE_RECORDER:
		
			pauseRecording();
			break;
		case RESUME_RECORDER:
		
			resumeRecording();
			break;
		default:
			break;
		}
	}

	public int getCommand() {
		return choice;
	}

	public void initRecorder() {
		boolean _error = false;
		try {
			if (null == _player) {
				_player = Manager
						.createPlayer("capture://audio?encoding=audio/amr");				
				_player.prefetch();
				_player.realize();
				_rcontrol = (RecordControl) _player.getControl("RecordControl");
				_output = new ByteArrayOutputStream();
				_rcontrol.setRecordStream(_output);
				
			}
			System.err.println("Player Instance Created: "+_player);
		} catch (IOException error) {
			_error = true;
		} catch (IllegalArgumentException error) {
			_error = true;
		} catch (IllegalStateException error) {
			_error = true;
		} catch (SecurityException error) {
			_error = true;
		} catch (MediaException error) {
			_error = true;
		} catch (Throwable error) {
			error.printStackTrace();
			_error = true;

		}
	
	}

	

	public void run() {
		
		try {
			recordingScreen.updateFocusForBottomPanel(false);
			_player.start();
			_rcontrol.startRecord();
			
		} catch (MediaException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	public byte[] getVoiceNote() {
		return _data;
	}

	public void pauseRecording() {
		//recordingScreen.updateFocusForBottomPanel(true);
		_rcontrol.stopRecord();
		
				
	}

	public void resumeRecording() {
		try {
			//recordingScreen.updateFocusForBottomPanel(false);
			_rcontrol.startRecord();
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}

	public byte[] getVoiceBufferForPreview() {
		
			
				//_rcontrol.stopRecord();
				try {
					_output.flush();
					_data = _output.toByteArray();
					System.err.println("_data = _output.toByteArray();"+_data+" "+_data.length);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
		return _data;
	}

	public byte[] getVoiceBuffer() {
		_data = null;
		try {
			if (null != _player && null != _rcontrol) {
				_rcontrol.stopRecord();
				_rcontrol.commit();
				_output.flush();
				_data = _output.toByteArray();
			}
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {

			e.printStackTrace();
		}
		return _data;
	}

	public void destroyPlayer() {
		try {
			if (null != _player) {
				_player.stop();
				freeAudioBuffer();
				_player.close();
				_player = null;
				_rcontrol = null;
			}
		} catch (MediaException me) {

		} catch (IllegalStateException me) {

		} catch (Exception ex) {

		}
		_player = null;
		_rcontrol = null;
	}

	public void freeAudioBuffer() {
		try {
			if (null != _output) {
				_output.close();
				_output = null;
			}
		} catch (IOException ioe) {

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

			e.printStackTrace();
		}
	}

	public int getVoiceBufferForTimeDisplay() {
		try {
			if (null != _player && null != _rcontrol) {
				_rcontrol.stopRecord();
			}
		} catch (Exception e) {

			e.printStackTrace();
		}
		return _output.size();
	}

	private void clearMemory() {
		try {
			System.gc();

		} catch (Throwable error) {
		}
	} 

}
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Grandstream GXP1620 Small to Medium Business HD IP Phone VoIP Phone and Device
$50.23
Grandstream GXP1620 Small to Medium Business HD IP Phone VoIP Phone and Device pictureNEC Aspire IP1NA-4TIXH 4 Button Black VoIP Phone 0890072
$89.99
NEC Aspire IP1NA-4TIXH 4 Button Black VoIP Phone 0890072  pictureGrandStream GXP2200 Enterprise Multimedia Android VOIP Speakerphone, No Stand
$109.99
GrandStream GXP2200 Enterprise Multimedia Android VOIP Speakerphone, No Stand pictureLOT OF 15 AASTRA 6757i 57i VOIP BUSINESS PHONES
$289.99
LOT OF 15 AASTRA 6757i 57i VOIP BUSINESS PHONES pictureLot of 3 Polycom SoundPoint IP550 SIP IP Business Phones VOiP
$60.75
Lot of 3 Polycom SoundPoint IP550 SIP IP Business Phones VOiP picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.