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

SMPTE Output Studio 16 Extras The Complete SMPTE Generator For Your Amiga
$14.99
SMPTE Output Studio 16 Extras The Complete SMPTE Generator For Your Amiga picture23 WAY "D" SHELL HOOD DB23 D23 DB23F DB23M FOR COMMODORE AMIGA CONNECTORS - RARE
$2.54
23 WAY Toshiba TMP68HC000P-16 16mhz 68000 CPU Chip, Amiga Atari Apple Mac
$22.0
Toshiba TMP68HC000P-16 16mhz 68000 CPU Chip, Amiga Atari Apple Mac pictureAMIGA AMIGA A107-335D RQAUS1
$36.1
AMIGA AMIGA A107-335D RQAUS1 pictureCommodore AMIGA CSG 8520 Chip IC 500/A500+/A2000 CDTV - NEW
$12.99
Commodore AMIGA CSG 8520 Chip IC  500/A500+/A2000 CDTV - NEW picture






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