×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Sep 2009
    Location
    Mysore,Karnataka,India
    Posts
    3

    Lightbulb Command or Canvas Events for Recording ?? Please Help..

    Hi I am Abhijith I am a total newbie to the j2me world, And I am learning it now,
    My project topic is "Bluetooth Walkie Talkie " , And I am trying my best and putting
    all my efforts to code incrementally by learning , Before I could implement bluetooth,
    I thought let me complete the recording The audio and playing part first,

    The recording and playing of audio is working fine , But i would like to do it a real manner as Real Walkie talkie does, I want to record audio ONLY when the Key is being
    pressed , and when its released it should exit the player hence saving the recorded file,
    (Actually i dont want to save it in future,i would be sending the bytearray though the bluetooth , but for now , I want the Current module to be ready)

    I tried my best searching online to implement my requirement but the couldnot find
    such events I found Canva's KEYPRESS, KEYRELEASE , etc events but they dint not
    serve my purpose, Let me clearly tell where I am stuck , After the midlet starts(by launching it) then i would like to press a key( keypressed say No 5) for certain
    amount of time and the audio should be recorded only for the keypressed duration ,
    after I release , it should stop recording and save as a wav file .

    Whats happening is When i keep the key pressed , The midlet asks whether to allow
    the recording , for this purpose when I release key the control is going out, and
    i am not able to achieve the needed , I am posting the code here, Please Help me.
    I am not asking for the complete spoon feeding or ready made code, But as a beginner
    I need help from you all to learn and implement it.(at least it should satisfy me,i would feel i have learnt something then)

    Here below is my code ( i AM using WTK 2.5 )

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import java.io.*;
    import javax.microedition.media.control.*;
    import java.util.*;
    import javax.microedition.io.*;
    import javax.microedition.io.file.*;

    public class Key extends MIDlet{
    private Display display;
    private KeyCodeCanvas canvas;

    public Key(){
    display = Display.getDisplay(this);
    canvas = new KeyCodeCanvas(this);
    }

    protected void startApp(){
    display.setCurrent(canvas);
    }

    protected void pauseApp(){}

    protected void destroyApp( boolean unconditional ){
    notifyDestroyed();
    }
    }

    class KeyCodeCanvas extends Canvas implements CommandListener{
    private Command exit;
    public StringItem message ;
    private Player player;
    private byte[] recordedAudioArray = null;
    private String keyValue = null;
    private Key midlet;
    Thread t = null;
    private String eventType = null;
    public KeyCodeCanvas(Key midlet){
    this.midlet = midlet;

    exit = new Command("Exit", Command.EXIT, 1);
    addCommand(exit);
    setCommandListener(this);
    }

    protected void paint(Graphics g){
    g.setColor(255, 0, 0);
    g.fillRect(0, 0, getWidth(), getHeight());

    if (keyValue != null){
    g.setColor(0, 0, 255);
    g.drawString(keyValue + eventType+message, getWidth() / 2, getHeight() / 2,
    Graphics.TOP | Graphics.HCENTER);
    }
    }

    public void commandAction(Command c, Displayable d){
    String label = c.getLabel();
    if(label.equals("Exit"))
    midlet.destroyApp(true);
    }

    protected void keyPressed(int keyCode){
    eventType = "pressed";
    keyValue = getKeyName(keyCode);
    repaint();
    }

    public void keyReleased(int keyCode)
    {
    try
    {
    eventType = "released";
    keyValue = getKeyName(keyCode);
    repaint();

    }
    catch (Exception e)
    {
    System.out.print(e);
    }
    }

    public void keyRepeated(int keyCode)
    {
    eventType = "repeated";
    keyValue = getKeyName(keyCode);
    try
    {
    Thread t1 = new Thread()
    {
    public void run()
    {
    try
    {
    player = Manager.createPlayer("capture://audio?encoding=pcm");
    player.realize();
    RecordControl rc = (RecordControl)player.getControl("RecordControl");
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    rc.setRecordStream(output);
    rc.startRecord();
    player.start();
    eventType = "Recording";
    message.setText("Recording...");
    Thread.sleep(5000);
    message.setText("Recording Done!");
    rc.commit();
    recordedAudioArray = output.toByteArray();
    player.close();
    }
    catch (Exception e)
    {
    }
    }
    }; t1.start();
    }
    catch (Exception e)
    {
    }
    repaint();
    }

    //Runnable r1 = new Runnable()
    //{
    // public void run()
    // {
    // try
    // {
    // System.out.print(" here in thread");
    // message.setText(" In thread now!! ");

    // player = Manager.createPlayer("capture://audio?encoding=pcm");
    // player.realize();
    // RecordControl rc = (RecordControl)player.getControl("RecordControl");
    // ByteArrayOutputStream output = new ByteArrayOutputStream();
    // rc.setRecordStream(output);
    // rc.startRecord();
    // player.start();
    // eventType = "Recording";
    // message.setText("Recording...");
    // Thread.sleep(5000);
    // message.setText("Recording Done!");
    // rc.commit();
    // recordedAudioArray = output.toByteArray();
    // player.close();
    // }
    // catch (Exception e)
    // {

    // }

    // }

    //};

    }
    I am really sorry at the end I messed with the code and its altered a Lot, But hope the
    logic Will is clear which is my requirement . I know the code for recording and
    playing is not complete as said, i Messed around a working code and tried adding Canavs
    for keyrepeat method,tried putting a thread around , AT last totally messed,

    I tried working on this for two days but couldn't be successfull , Please Help me!!
    The control goes out when midlet asks whether to allow recording ,
    I thank you anticipation ...

    -Abhijith Rao

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: Command or Canvas Events for Recording ?? Please Help..

    Quote Originally Posted by abhijithrao View Post
    Hi I am Abhijith I am a total newbie to the j2me world, And I am learning it now,
    My project topic is "Bluetooth Walkie Talkie " , And I am trying my best and putting
    all my efforts to code incrementally by learning , Before I could implement bluetooth,
    I thought let me complete the recording The audio and playing part first,

    The recording and playing of audio is working fine , But i would like to do it a real manner as Real Walkie talkie does, I want to record audio ONLY when the Key is being
    pressed , and when its released it should exit the player hence saving the recorded file,
    (Actually i dont want to save it in future,i would be sending the bytearray though the bluetooth , but for now , I want the Current module to be ready)

    I tried my best searching online to implement my requirement but the couldnot find
    such events I found Canva's KEYPRESS, KEYRELEASE , etc events but they dint not
    serve my purpose, Let me clearly tell where I am stuck , After the midlet starts(by launching it) then i would like to press a key( keypressed say No 5) for certain
    amount of time and the audio should be recorded only for the keypressed duration ,
    after I release , it should stop recording and save as a wav file .

    Whats happening is When i keep the key pressed , The midlet asks whether to allow
    the recording , for this purpose when I release key the control is going out, and
    i am not able to achieve the needed , I am posting the code here, Please Help me.
    I am not asking for the complete spoon feeding or ready made code, But as a beginner
    I need help from you all to learn and implement it.(at least it should satisfy me,i would feel i have learnt something then)

    Here below is my code ( i AM using WTK 2.5 )



    I am really sorry at the end I messed with the code and its altered a Lot, But hope the
    logic Will is clear which is my requirement . I know the code for recording and
    playing is not complete as said, i Messed around a working code and tried adding Canavs
    for keyrepeat method,tried putting a thread around , AT last totally messed,

    I tried working on this for two days but couldn't be successfull , Please Help me!!
    The control goes out when midlet asks whether to allow recording ,
    I thank you anticipation ...

    -Abhijith Rao

    Steps:
    Take Boolean variable talk=false;
    In Keypresss make it true;
    In KeyRelease make it false;

    Inclose your Thread.Sleep(5000) // while you are recording..
    In a do while(talk) loop like this.
    while(talk)
    {
    Thread.sleep(50
    }

    thanks,
    ~Amitabh
    (Poster of the Month -Aug'09)
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Nokia Developer Champion
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: Command or Canvas Events for Recording ?? Please Help..

    First of all tell me that :

    1. Whats the need of pressing the key continuously.
    2. What u did at the alert asking for permission for Recording.
    3. Had u handle the exceptions at any place(Im unable to see the exception handling so far in ur code).
    4. Why dont u stop the the player before closing it. In ur code u r closing the Player without stop it.


    check and reply..
    thanks,
    jitu_goldie..

    KEEP TRYING..

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: Command or Canvas Events for Recording ?? Please Help..

    Abhijith wants to give his users a real experiance of PUSH to TALK from his app using Bluetooth, thus he wants to record only for as much time as user keeps a key pressed.

    @Abhijith
    Try the boolean thing that I suggested and see if it works for you.
    Do add some error/exception handling in your code and stop the players before closing them.

    thanks,
    ~Amitabh
    (Poster of the Month -Aug'09)
    Follow me on my blog for Innovative Mobile Apps

  5. #5
    Registered User
    Join Date
    Sep 2009
    Location
    Mysore,Karnataka,India
    Posts
    3

    Re: Command or Canvas Events for Recording ?? Please Help..

    Thanks Amitabh for your suggestion ....
    Here below I am pasting the code
    (or for your ref i am uploading to my homepage
    http://home.no/abyssman/KeyCodesMIDlet.java
    My voice recording file
    http://home.no/abyssman/VoiceRecordMidlet.java
    )
    Amitabh i tried what you said ,have i done it right,At least?? I am really sorry if its wrong,
    This code is not executing its giving me errors, I am really sorry I am not able to make it,I tried my best...
    The following are the errors
    Running in the identified_third_party security domain
    Uncaught exception java/lang/NoClassDefFoundError: KeyCodesMidlet.

    ---------------------------------------------------------

    I dont know where am i going wrong,
    Amitabh You are right the things which you
    have specified are my requirements...

    jitu_goldie
    Code:
     2. What u did at the alert asking for permission for Recording.
    I had to release the key which i was holding and Had to press the command "YES" For letting the midlet to record the audio, I think here The control was going out and used to not come back

    I am unable to think of the logic, Being just at academics I am brooding over having no knowledge at programming .


    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import java.io.*;
    import javax.microedition.media.control.*;
    import java.util.*;
    import javax.microedition.io.*;
    import javax.microedition.io.file.*;
    
    public class KeyCodesMIDlet extends MIDlet
    {
    	private Display  display;
    	private KeyCodeCanvas canvas;
    
    	public KeyCodesMIDlet(){
    		display = Display.getDisplay(this);
    		canvas  = new KeyCodeCanvas(this);
    	}
    
    	protected void startApp(){
    		display.setCurrent(canvas);
    	}
    
    	protected void pauseApp(){}
    
    	protected void destroyApp( boolean unconditional ){
    		notifyDestroyed();
    	}
    }
    
    class KeyCodeCanvas extends Canvas implements CommandListener
    {
    	private Command exit;
    	private String keyValue = null;
    	private KeyCodesMIDlet midlet;
            private Player player;
            private byte[] recordedAudioArray = null;
    	//my code
    	public StringItem message ;
    	Thread t = null;
    	
    	//Thread t1 =null;
    	private String eventType = null;
        //let me take a boolean variable talk and set it false	
    	boolean talk = false;
     //end of my code
     
    	public KeyCodeCanvas(KeyCodesMIDlet midlet){
    		this.midlet = midlet;
    
    		exit = new Command("Exit", Command.EXIT, 1);
    		addCommand(exit);
    		setCommandListener(this);
    	} 
    
    	protected void paint(Graphics g){
    		g.setColor(255, 0, 0);
    		g.fillRect(0, 0, getWidth(), getHeight());
    
    		if (keyValue != null){
    			g.setColor(0, 0, 255);
    			g.drawString(keyValue +eventType + message, getWidth()/2, getHeight()/2, Graphics.TOP | Graphics.HCENTER);
    		}
    	}
    
    	public void commandAction(Command c, Displayable d){
    		String label = c.getLabel();
    		if(label.equals("Exit"))
    			midlet.destroyApp(true);
    	}
    
    	public void keyPressed(int keyCode)
    	{
    		eventType = "pressed";
    		keyValue = getKeyName(keyCode);
    		//lets make true when we keep the key pressed
        	
        	talk=true;
    		repaint();
    	}
    	
    	
    	public void keyRelesed(int keyCode)
    	{
    		eventType = "released";
    		keyValue = getKeyName(keyCode);
    		// lets make the talk variable as false here so that
    		
    		talk=false;
    		
    		repaint();
    		
    	}
    	
    	 public void keyRepeated(int keyCode)
    	{
    		//try{
    			
    			eventType ="repeated";
    			keyValue = getKeyName(keyCode);
    	
    		
    			talk=true;
    	
    			
    			t1.start();
    	//	}
    
    	//	catch (Exception e)
    	//	{
    	//		System.out.print("Exception in Keyrepeated");
    	//	}		
    		repaint();
    	}
    		
    	
    		  Thread t1 = new Thread()
    		  {
    			  public void run()
    			  {
    				  try{
    					  player = Manager.createPlayer("capture://audio?encoding=pcm");
    					  player.realize();
    					  RecordControl rc = (RecordControl)player.getControl("RecordControl");
    					  ByteArrayOutputStream output = new ByteArrayOutputStream();
    					  rc.setRecordStream(output);
    					  rc.startRecord();
    					  player.start();
    					  eventType = "Recording";
    					  message.setText("Recording...");
    					//Here while its recording let me make it sleep until talk
    					//becomes false ,...
    					  while(talk)
    						{
    							Thread.sleep(100);
    						}	
    					  message.setText("Recording Done!");
    					  player.stop();
    					  rc.commit();
    					  recordedAudioArray = output.toByteArray();
    					  player.close();
    				  }
    				  catch (Exception e)
    				  {
    				  	//System.out.print("probable exception in player inside thread");
    				  }
    			  }
    		  };
    	  }
    Please guide me , I will try learning , Suggest me I would definitely follow what ever you say.
    I am not still not getting how it my requirement can be implemented,
    when the midlet gets launched, I would press or hold any key for initiating the record action but once it is yet to begin it will ask permission for recording,
    here i need to Give yes ,Where is the control now? And how to get control back to player or recording,logic is out of reach , tell me the logic how is it really working or how it should be implemented ?
    I thank you in anticipation ...

    -Abhijith
    Last edited by abhijithrao; 2009-09-20 at 00:44. Reason: few more lines had to be added up..
    Abhijith

    "Known is a Drop , Unknown Is An Ocean "

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: Command or Canvas Events for Recording ?? Please Help..

    Test your app in emulator, tieing it up with the emulator in trusted midlet domian and pre-set all the required permission for recoding. Once all this done, while you test on emulator and Press '5' to start the recoding, your emulator will not ask for permission to allow recording. If it happens... then you need at lesat 3rd party trust certificate for your app to run on the device.

    Which is your traget device, try setting the permissions for recording for your app on the device using app manager to allow always and it should work on device too.

    thanks,
    ~Amitabh
    (Poster of the Month -Aug'09)
    Follow me on my blog for Innovative Mobile Apps

  7. #7
    Registered User
    Join Date
    Sep 2009
    Location
    Mysore,Karnataka,India
    Posts
    3

    Re: Command or Canvas Events for Recording ?? Please Help..

    Amitabh sir ,
    I am using Sun Java wireless toolkit 2.51 and as you said I changed the settings
    for the midlet and permissions were set for recording and saving as file even.

    But Please check my code and tell where is the error coming now , whats
    wrong with my exception handling part, I am unable to trace , Please help me
    and correct the code , Its my kind request.

    Building "KeyCodesMidlet"
    C:\Documents and Settings\Abhijith\j2mewtk\2.5.2\apps\KeyCodesMidlet\src\KeyCodesMIDlet.java:122: illegal start of type
    try{
    ^
    C:\Documents and Settings\Abhijith\j2mewtk\2.5.2\apps\KeyCodesMidlet\src\KeyCodesMIDlet.java:122: ';' expected
    try{
    ^
    C:\Documents and Settings\Abhijith\j2mewtk\2.5.2\apps\KeyCodesMidlet\src\KeyCodesMIDlet.java:125: <identifier> expected
    t1 = new Thread()
    ^
    C:\Documents and Settings\Abhijith\j2mewtk\2.5.2\apps\KeyCodesMidlet\src\KeyCodesMIDlet.java:158: class or interface expected
    catch(Exception e)
    ^
    C:\Documents and Settings\Abhijith\j2mewtk\2.5.2\apps\KeyCodesMidlet\src\KeyCodesMIDlet.java:162: class or interface expected
    }
    ^
    5 errors
    com.sun.kvem.ktools.ExecutionException
    Build failed

    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import java.io.*;
    import javax.microedition.media.control.*;
    import java.util.*;
    import javax.microedition.io.*;
    import javax.microedition.io.file.*;
    
    public class KeyCodesMIDlet extends MIDlet
    {
    	private Display  display;
    	private KeyCodeCanvas canvas;
    
    	public KeyCodesMIDlet(){
    		display = Display.getDisplay(this);
    		canvas  = new KeyCodeCanvas(this);
    	}
    
    	protected void startApp(){
    		display.setCurrent(canvas);
    	}
    
    	protected void pauseApp(){}
    
    	protected void destroyApp( boolean unconditional )
            {
    		notifyDestroyed();
    	}
    }
    
    class KeyCodeCanvas extends Canvas implements CommandListener
    {
    	private Command exit;
    	private String keyValue = null;
    	private KeyCodesMIDlet midlet;
            private Player player;
            private byte[] recordedAudioArray = null;
    	//my code
    	public StringItem message ;
    	Thread t = null;
    	
    	Thread t1 =null;
    	private String eventType = null;
        //let me take a boolean variable talk and set it false	
    	boolean talk = false;
     //end of my code
     
    	public KeyCodeCanvas(KeyCodesMIDlet midlet)
            {
    		this.midlet = midlet;
    
    		exit = new Command("Exit", Command.EXIT, 1);
    		addCommand(exit);
    		setCommandListener(this);
    	} 
    
    	protected void paint(Graphics g)
            {
    		g.setColor(255, 0, 0);
    		g.fillRect(0, 0, getWidth(), getHeight());
    
    		if (keyValue != null)
                    {
    			g.setColor(0, 0, 255);
    			g.drawString(keyValue +eventType + message, getWidth()/2, getHeight()/2, Graphics.TOP | Graphics.HCENTER);
    		}
    	}
    
    	public void commandAction(Command c, Displayable d)
            {
    		String label = c.getLabel();
    		if(label.equals("Exit"))
    			midlet.destroyApp(true);
    	}
    
    	public void keyPressed(int keyCode)
    	{
    		eventType = "pressed";
    		keyValue = getKeyName(keyCode);
    		//lets make true when we keep the key pressed
        	
        	talk=true;
    		repaint();
    	}
    	
    	
    	public void keyRelesed(int keyCode)
    	{
    		eventType = "released";
    		keyValue = getKeyName(keyCode);
    		// lets make the talk variable as false here so that
    		
    		talk=false;
    		
    		repaint();
    		
    	}
    	
    	 public void keyRepeated(int keyCode)
    	{
    		//try{
    			
    			eventType ="repeated";
    			keyValue = getKeyName(keyCode);
    	
    		
    			talk=true;
    	
    			
    			//t1.start();
                            
    	//	}
    
    	//	catch (Exception e)
    	//	{
    	//		System.out.print("Exception in Keyrepeated");
    	//	}		
    		repaint();
    	}
    
             try{
    
    
    		   t1 = new Thread()
    		  {
    			  public void run()
    			  {
    				  try{
    					  player = Manager.createPlayer("capture://audio?encoding=pcm");
    					  player.realize();
    					  RecordControl rc = (RecordControl)player.getControl("RecordControl");
    					  ByteArrayOutputStream output = new ByteArrayOutputStream();
    					  rc.setRecordStream(output);
    					  rc.startRecord();
    					  player.start();
    					  eventType = "Recording";
    					  message.setText("Recording...");
    					//Here while its recording let me make it sleep until talk
    					//becomes false ,...
    					  while(talk)
    						{
    							Thread.sleep(100);
    						}	
    					  message.setText("Recording Done!");
    					  player.stop();
    					  rc.commit();
    					  recordedAudioArray = output.toByteArray();
    					  player.close();
    				  }
    				  catch (Exception e)
    				  {
    				  	//System.out.print("probable exception in player inside thread");
    				  }
    			  }
    		  };
    	  }
            catch(Exception e)
            {
                System.out.print(e);
                
            }
                    
    
    
    }
    Abhijith

    "Known is a Drop , Unknown Is An Ocean "

  8. #8
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: Command or Canvas Events for Recording ?? Please Help..

    Quote Originally Posted by abhijithrao View Post
    Amitabh sir ,
    I am using Sun Java wireless toolkit 2.51 and as you said I changed the settings
    for the midlet and permissions were set for recording and saving as file even.

    But Please check my code and tell where is the error coming now , whats
    wrong with my exception handling part, I am unable to trace , Please help me
    and correct the code , Its my kind request.

    Building "KeyCodesMidlet"
    C:\Documents and Settings\Abhijith\j2mewtk\2.5.2\apps\KeyCodesMidlet\src\KeyCodesMIDlet.java:122: illegal start of type
    try{
    ^
    C:\Documents and Settings\Abhijith\j2mewtk\2.5.2\apps\KeyCodesMidlet\src\KeyCodesMIDlet.java:122: ';' expected
    try{
    ^
    C:\Documents and Settings\Abhijith\j2mewtk\2.5.2\apps\KeyCodesMidlet\src\KeyCodesMIDlet.java:125: <identifier> expected
    t1 = new Thread()
    ^
    C:\Documents and Settings\Abhijith\j2mewtk\2.5.2\apps\KeyCodesMidlet\src\KeyCodesMIDlet.java:158: class or interface expected
    catch(Exception e)
    ^
    C:\Documents and Settings\Abhijith\j2mewtk\2.5.2\apps\KeyCodesMidlet\src\KeyCodesMIDlet.java:162: class or interface expected
    }
    ^
    5 errors
    com.sun.kvem.ktools.ExecutionException
    Build failed

    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import java.io.*;
    import javax.microedition.media.control.*;
    import java.util.*;
    import javax.microedition.io.*;
    import javax.microedition.io.file.*;
    
    public class KeyCodesMIDlet extends MIDlet
    {
    	private Display  display;
    	private KeyCodeCanvas canvas;
    
    	public KeyCodesMIDlet(){
    		display = Display.getDisplay(this);
    		canvas  = new KeyCodeCanvas(this);
    	}
    
    	protected void startApp(){
    		display.setCurrent(canvas);
    	}
    
    	protected void pauseApp(){}
    
    	protected void destroyApp( boolean unconditional )
            {
    		notifyDestroyed();
    	}
    }
    
    class KeyCodeCanvas extends Canvas implements CommandListener
    {
    	private Command exit;
    	private String keyValue = null;
    	private KeyCodesMIDlet midlet;
            private Player player;
            private byte[] recordedAudioArray = null;
    	//my code
    	public StringItem message ;
    	Thread t = null;
    	
    	Thread t1 =null;
    	private String eventType = null;
        //let me take a boolean variable talk and set it false	
    	boolean talk = false;
     //end of my code
     
    	public KeyCodeCanvas(KeyCodesMIDlet midlet)
            {
    		this.midlet = midlet;
    
    		exit = new Command("Exit", Command.EXIT, 1);
    		addCommand(exit);
    		setCommandListener(this);
    	} 
    
    	protected void paint(Graphics g)
            {
    		g.setColor(255, 0, 0);
    		g.fillRect(0, 0, getWidth(), getHeight());
    
    		if (keyValue != null)
                    {
    			g.setColor(0, 0, 255);
    			g.drawString(keyValue +eventType + message, getWidth()/2, getHeight()/2, Graphics.TOP | Graphics.HCENTER);
    		}
    	}
    
    	public void commandAction(Command c, Displayable d)
            {
    		String label = c.getLabel();
    		if(label.equals("Exit"))
    			midlet.destroyApp(true);
    	}
    
    	public void keyPressed(int keyCode)
    	{
    		eventType = "pressed";
    		keyValue = getKeyName(keyCode);
    		//lets make true when we keep the key pressed
        	
        	talk=true;
    		repaint();
    	}
    	
    	
    	public void keyRelesed(int keyCode)
    	{
    		eventType = "released";
    		keyValue = getKeyName(keyCode);
    		// lets make the talk variable as false here so that
    		
    		talk=false;
    		
    		repaint();
    		
    	}
    	
    	 public void keyRepeated(int keyCode)
    	{
    		//try{
    			
    			eventType ="repeated";
    			keyValue = getKeyName(keyCode);
    	
    		
    			talk=true;
    	
    			
    			//t1.start();
                            
    	//	}
    
    	//	catch (Exception e)
    	//	{
    	//		System.out.print("Exception in Keyrepeated");
    	//	}		
    		repaint();
    	}
    
             try{
    
    
    		   t1 = new Thread()
    		  {
    			  public void run()
    			  {
    				  try{
    					  player = Manager.createPlayer("capture://audio?encoding=pcm");
    					  player.realize();
    					  RecordControl rc = (RecordControl)player.getControl("RecordControl");
    					  ByteArrayOutputStream output = new ByteArrayOutputStream();
    					  rc.setRecordStream(output);
    					  rc.startRecord();
    					  player.start();
    					  eventType = "Recording";
    					  message.setText("Recording...");
    					//Here while its recording let me make it sleep until talk
    					//becomes false ,...
    					  while(talk)
    						{
    							Thread.sleep(100);
    						}	
    					  message.setText("Recording Done!");
    					  player.stop();
    					  rc.commit();
    					  recordedAudioArray = output.toByteArray();
    					  player.close();
    				  }
    				  catch (Exception e)
    				  {
    				  	//System.out.print("probable exception in player inside thread");
    				  }
    			  }
    		  };
    	  }
            catch(Exception e)
            {
                System.out.print(e);
                
            }
                    
    
    
    }
    Please resolve the simple Java Compilation erros in your IDE and then if you code doesnt work post it here.... its difficult to resolve complination errors with our daily work load, we can help you with logic's/workarounds but cant work on your code as such.

    I hope you understand...

    thanks,
    ~Amitabh
    (Poster of the Month -Aug'09)
    Follow me on my blog for Innovative Mobile Apps

Similar Threads

  1. Replies: 1
    Last Post: 2009-09-08, 03:32
  2. Simulate key events
    By priteshgajjar in forum Symbian User Interface
    Replies: 7
    Last Post: 2009-04-30, 08:04
  3. Handling CCoeControl events without AddToStackL
    By LavanyaSpm in forum Symbian
    Replies: 2
    Last Post: 2009-02-10, 06:09
  4. Replies: 0
    Last Post: 2007-04-03, 17:22
  5. Catching events with RSystemAgent
    By d00mo in forum Symbian
    Replies: 3
    Last Post: 2005-06-27, 18:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •