BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 10-08-2010, 08:51 AM   #1
8vius
New Member
 
Join Date: Oct 2010
Model: 8520
PIN: N/A
Carrier: Digitel
Posts: 4
Default Time limiting voice recording

Please Login to Remove!

Hey all, i'm new to BB development and i'm making a voice recording and playback app. I've managed to record, stop the recording and playback the recording, i'd like to know if there's a way i can put a time limit on the recording and also how to display a timer on the screen. Here's a sample of the Thread i use to do the tasks

Code:
package Clases;

import java.io.*;
import java.lang.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;

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

public class AudioRecorderThread extends Thread implements javax.microedition.media.PlayerListener{

	private Player _player;
    private RecordControl _recordControl;
    private ByteArrayOutputStream output;
    private ByteArrayInputStream input;
    
    private byte[] _audioArray = null; 
    public byte[] get_audioArray() {
		return _audioArray;
	}



	AudioRecorderThread()
    {
		output = new ByteArrayOutputStream();
	
    }

	
	public void playerUpdate(Player player, String event, Object eventData) {
		// TODO Auto-generated method stub
		
	}
	
	public void run() 
	{
	
		try 
	    {
	        _player = Manager.createPlayer("capture://audio?encoding=audio/amr");
	        _player.addPlayerListener(this);
	        _player.realize();
	        _recordControl = (RecordControl) _player.getControl( "RecordControl" );
	        _recordControl.setRecordStream(output);
	        _recordControl.startRecord();
	        _player.start();
	        
	        
	        
	    }
	    catch( IOException e ) 
	    {
	        Dialog.alert(e.toString());
	    }
	    catch( MediaException e ) 
	    {
	        Dialog.alert(e.toString());
	    }
	}
	
	 public void stop() 
     {
         if (_player != null) 
         {
              _player.close();
              _player = null;
         }

         if (_recordControl != null) 
         {
                    
             try 
             {
                 _recordControl.commit();
                 _audioArray = output.toByteArray();
             } 
             catch (Exception e) 
             {
                 Dialog.alert(e.toString());
             }
             _recordControl = null;
         } 
     }
	 
	 public void play()
	 {
		
		 try {
			 input = new ByteArrayInputStream(_audioArray);
			 _player = Manager.createPlayer(input, "audio/x-wav");
			 _player.realize();
			 
			 VolumeControl volume = (VolumeControl)_player.getControl("VolumeControl");
			 volume.setLevel(100);
			 
			 _player.prefetch();
			 _player.start();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MediaException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	 }
	 


}
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


JCWY Voice Amplifier Wireless for Teachers Portable Rechargeable Mini Headset. 6 picture

JCWY Voice Amplifier Wireless for Teachers Portable Rechargeable Mini Headset. 6

$59.00



KEYENCE LR-TB5000CL Laser Sensor with Built-in Amplifier picture

KEYENCE LR-TB5000CL Laser Sensor with Built-in Amplifier

$289.99



Portable Voice Amplifier, Towevine Rechargeable Microphone Speaker picture

Portable Voice Amplifier, Towevine Rechargeable Microphone Speaker

$14.99



Phoenix Contact MACX MCR-EX-SL-2NAM-T Ex i NAMUR isolating amplifier - 2-chan... picture

Phoenix Contact MACX MCR-EX-SL-2NAM-T Ex i NAMUR isolating amplifier - 2-chan...

$296.32



Biamp Tesira AMP-450BP AVB/TSN Enabled 4 Channel Amplifier w/ PoE+ (G155) picture

Biamp Tesira AMP-450BP AVB/TSN Enabled 4 Channel Amplifier w/ PoE+ (G155)

$250.00



New In Box MITSUBISHI MR-J2S-60A AC Servo Amplifier Drive picture

New In Box MITSUBISHI MR-J2S-60A AC Servo Amplifier Drive

$185.00







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