BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-14-2008, 01:12 AM   #1 (permalink)
New Member
 
Join Date: Sep 2008
Model: 9000
PIN: N/A
Carrier: dhfkdhf
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Voice-recording in BB bold

Please Login to Remove!

Hi All,

I am working on voice recording. can anybody give suggestion or any sample code aboubt that?
Thanks in advance,

MM.
Offline  
Old 10-17-2008, 06:41 AM   #2 (permalink)
New Member
 
Join Date: Sep 2008
Model: 9000
PIN: N/A
Carrier: dhfkdhf
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi All,

for Voice recording i am not getting the output. by debugging the program , i understood that its not checking the conditions. that means, its always showing null value for VideoControl. I am posting my code. Please reply me as soon as possible. I am in hurry.

Thanks in advance.




package com.rim.player;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Canvas;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import javax.microedition.media.control.RecordControl;
import javax.microedition.media.control.VideoControl;
import javax.microedition.media.control.VolumeControl;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.HorizontalFieldMan ager;
import net.rim.device.api.ui.container.MainScreen;

public class Voice extends UiApplication{

public static void main(String[] args){
Voice voice = new Voice();
voice.enterEventDispatcher();
}
public Voice(){
Recorder screen = new Recorder();
pushScreen(screen);
}

// A UI screen to display our media player.
class Recorder extends MainScreen implements FieldChangeListener , PlayerListener{
private Player p;
private VolumeControl _volumeControl;
private RichTextField _statusField;
private ButtonField _controlButton;
private Field _recordField;
private Recorder _mainScreen;

private LabelField _currentTime;
private LabelField _duration;
private LabelField _volumeDisplay;

private TimerUpdateThread _timerUpdateThread;
private BasicEditField _videoField;

Recorder(){
_mainScreen = this;
setTitle("Voice Recording Demo");
_statusField = new RichTextField("Loading recorder, please wait...");
add(_statusField);

UiApplication.getUiApplication().invokeLater(new Runnable() {


private Player recordPlayer;
private RecordControl rc;
private String encoding_type;
private ByteArrayOutputStream output;
private Canvas canvas;
/**/ private VideoControl _videoControl;

//private VideoControl vc = (VideoControl)p.getControl( "javax.microedition.media.control.VideoControl ");
//private VideoControl vc = ;


public void run() {


try {
Player p = Manager.createPlayer("capture://audio?encoding=amr");
p.realize();
VideoControl vc = (VideoControl)p.getControl("Voice Dialing");


// start the Player and record for 7 seceonds.
rc = (RecordControl)p.getControl("RecordControl");
output = new ByteArrayOutputStream();
rc.setRecordStream(output);
rc.setRecordSizeLimit(20);
rc.startRecord();
p.start();
Thread.sleep(7000);
rc.commit();
p.close();
if (vc != null) {
vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null);//USE_DIRECT_VIDEO, canvas);
vc.setDisplayFullScreen(true);
vc.setVisible(true);

addFields();
}
else
{
_statusField.setText("Error: Could not load media");
}



} catch (IOException ioe) {
} catch (MediaException me) {
} catch (InterruptedException ie) {}


// if(_videoField != null)
// {
// addFields();
// }
// else
// {
// _statusField.setText("Error: Could not load media");
// }
}
});
}

private void addFields()
{
delete(_statusField);
add(_videoField);
HorizontalFieldManager hfm1 = new HorizontalFieldManager(Field.FIELD_HCENTER);
_controlButton = new ButtonField("Start");
_controlButton.setChangeListener(this);
hfm1.add(_controlButton);
add(hfm1);

HorizontalFieldManager hfm2 = new HorizontalFieldManager(Field.FIELD_HCENTER);
_currentTime = new LabelField("-");
_duration = new LabelField("- s");

hfm2.add(_currentTime);
hfm2.add(new LabelField(" / "));
hfm2.add(_duration);
hfm2.add(new LabelField("\t\t"));

add(hfm2);
}




public void fieldChanged(Field field, int context)
{
if (_controlButton.getLabel().equals("Start"))
{
try
{

p.start();

_timerUpdateThread = new TimerUpdateThread();
_timerUpdateThread.start();
}
catch(MediaException pe)
{
System.out.println(pe.toString());
}
}
else
{
try
{

p.stop();

_timerUpdateThread.stop();
}
catch(MediaException pe)
{
System.out.println(pe.toString());
}
}
}
public void playerUpdate(Player player, final String event, Object eventData)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{

public void run()
{


Dialog.alert(p.toString());
if (event.equals(VOLUME_CHANGED))
{
_volumeDisplay.setText("Volume : " + _volumeControl.getLevel());
}
else if (event.equals(STARTED ))
{
_currentTime.setText(" ");
_controlButton.setLabel("Pause");
}
else if (event.equals(STOPPED))
{
_currentTime.setText(p.getMediaTime()/1000000 + "");
_controlButton.setLabel("Start");
}
else if (event.equals(DURATION_UPDATED))
{
_duration.setText(p.getDuration()/1000000 + " s");
}
else if (event.equals(END_OF_MEDIA))
{
_controlButton.setLabel("Start");
}
}
});
}
protected boolean invokeAction(int action)
{
boolean handled = super.invokeAction(action);

if(!handled)
{
switch(action)
{
case ACTION_INVOKE: // Trackball click.
{
return true;
}
}
}
return handled;
}


protected boolean onSavePrompt()
{
return true;
}

private class TimerUpdateThread extends Thread
{
private boolean _threadCanRun;

public void run()
{
_threadCanRun = true;
while( _threadCanRun ) {
UiApplication.getUiApplication().invokeLater( new Runnable() {
public void run()
{
_currentTime.setText( p.getDuration() / 1000000 + "" );
}
} );

try {
Thread.sleep( 500L );
} catch( InterruptedException e ) {
}
}
}

public void stop()
{
_threadCanRun = false;
}
}
}
}

Last edited by dolan : 10-17-2008 at 06:42 AM.
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





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