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

BTS6143D Infineon Power Switch High-Side MOSFET Transistor DPAK-5 SMT NOS Qty 5
$4.99
BTS6143D Infineon Power Switch High-Side MOSFET Transistor DPAK-5 SMT NOS Qty 5 picture20L Silicon Si NPN Transistor Vintage 1968 - NOS Qty 2
$11.99
20L Silicon Si NPN Transistor Vintage 1968 - NOS Qty 2 pictureCM400DY-24A Factory New and Orig IGBT by Mitsu/Powerex
$165.0
CM400DY-24A Factory New and Orig IGBT by Mitsu/Powerex picture100Pcs NPN Transistor TO-92 2N2222A 2N2222 US SHIPPING M293
$3.99
100Pcs NPN Transistor TO-92 2N2222A 2N2222 US SHIPPING M293 picture5 Pcs AD558 AD558JN Ic Dac 8Bit V-Out 16-Dip
$9.3
5 Pcs AD558 AD558JN Ic Dac 8Bit V-Out 16-Dip picture






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