1. rashmi.rrb's Avatar
    Here is my code,I am unable to record the file input,please let me know where I am going wrong

    /*
    * AudioScreen.java
    *
    * � <your company here>, <year>
    * Confidential and proprietary.
    */

    package com.sairam;

    import net.rim.device.api.ui.*;
    import javax.microedition.media.*;
    import net.rim.device.api.ui.container.*;
    import net.rim.device.api.ui.component.ButtonField;
    import javax.microedition.media.Player;
    import javax.microedition.media.control.*;
    import java.io.*;
    import javax.microedition.io.Connector;
    import javax.microedition.media.Manager;
    import java.io.ByteArrayOutputStream;
    import javax.microedition.io.file.FileConnection;
    import javax.microedition.io.file .*;




    public class AudioRecordingMainScreen extends MainScreen implements FieldChangeListener
    {
    ButtonField recordbtn,playbtn;
    Player player;
    RecordControl rccontrol;
    ByteArrayOutputStream byteos;
    ByteArrayInputStream byteis;
    public VolumeControl vc;


    //filepath="file:///SdCard/";

    public AudioRecordingMainScreen()
    {
    recordbtn=new ButtonField("Record",ButtonField.CONSUME_CLICK);
    playbtn=new ButtonField("Stop",ButtonField.CONSUME_CLICK);
    add(recordbtn);
    add(playbtn);
    recordbtn.setChangeListener(this);
    playbtn.setChangeListener(this);

    }

    public void fieldChanged(Field field,int context)
    {
    if(field==recordbtn)
    {
    record();

    }
    else if(field==playbtn)
    {
    stop();

    }

    }

    public void record()
    {
    try
    {
    player=Manager.createPlayer("capture://audio?encoding=amr");
    player.realize();
    rccontrol=(RecordControl)player.getControl("Record Control");
    ByteArrayOutputStream byteos=new ByteArrayOutputStream();
    rccontrol.setRecordStream(byteos);
    FileConnection fconn=(FileConnection)Connector.open("file:///SDCard/BlackBerry/voicenotes/AudioRecording.amr");
    if(!fconn.exists())
    {
    fconn.create();
    }
    // OutputStream dataos=fconn.openDataOutputStream();


    rccontrol.startRecord();
    //rccontrol.setRecordLocation("C://SDCard/BlackBerry/voicenotes/wer.amr");
    rccontrol.setRecordLocation("file:///C:/SDCard/BlackBerry/voicenotes/AudioRecording.amr");

    player.start();
    Thread.currentThread().sleep(5000);
    rccontrol.commit();
    player.close();


    }
    catch(final Exception e)
    {

    e.printStackTrace();

    }
    }

    public void stop()
    {

    /*{
    rccontrol.stopRecord();

    rccontrol.commit();
    byte[] data=byteos.toByteArray();
    byteos.close();
    player.close();

    byteis=new ByteArrayInputStream(data);
    player=Manager.createPlayer(byteis,"audio/amr");
    player.realize();
    player.start();
    }*/
    try{
    InputStream is= getClass().getResourceAsStream("AudioRecording.amr ");
    player =Manager.createPlayer(is,"audio/amr");
    player.realize();
    vc=(VolumeControl)player.getControl("VolumeControl ");
    vc.setLevel(100);
    player.start();
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }}
    10-14-10 01:08 AM
LINK TO POST COPIED TO CLIPBOARD