BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 10-14-2008, 12:12 AM   #1
dolan
New Member
 
Join Date: Sep 2008
Model: 9000
PIN: N/A
Carrier: dhfkdhf
Posts: 12
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, 05:41 AM   #2
dolan
New Member
 
Join Date: Sep 2008
Model: 9000
PIN: N/A
Carrier: dhfkdhf
Posts: 12
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 05:42 AM..
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Dell Poweredge R610 picture

Dell Poweredge R610

$100.00



INTEL S5000PSL Multi-Core Xeon Motherboard / Server Board w/ 2X L5420 & 2X2G RAM picture

INTEL S5000PSL Multi-Core Xeon Motherboard / Server Board w/ 2X L5420 & 2X2G RAM

$61.62



Super SuperMicro X7DVL-E Intel Xeon Server Mother Board dual CPU sockets SL9RX picture

Super SuperMicro X7DVL-E Intel Xeon Server Mother Board dual CPU sockets SL9RX

$75.00



DELL PowerEdge R310 Server picture

DELL PowerEdge R310 Server

$80.00



NETWORK INSTRUMENT GIGASTOR- 2U (2X) XEON E5-2630- 64 GB PC3 RAM picture

NETWORK INSTRUMENT GIGASTOR- 2U (2X) XEON E5-2630- 64 GB PC3 RAM

$293.99



Trenton 92-506313-XXX W/ 2x Intel Xeon Processors & 4GB DDR2 RAM picture

Trenton 92-506313-XXX W/ 2x Intel Xeon Processors & 4GB DDR2 RAM

$110.00







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