×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    3

    Post Capture Audio wont work on N95 8GB

    Hi,
    The code works fine on the WTK Emulator, but I just can't figure out why it wont work on the N95/Symbian Emulator or phone..
    Can anyone please tell me what is wrong?

    Thx in advance!

    ******************App.java******************
    package Project;

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;

    public class App extends MIDlet {

    Display display;
    Mixer mCanvas;
    public App() {
    }

    protected void startApp() {

    mCanvas = new Mixer("DJJLAGT");
    display = Display.getDisplay(this);
    display.setCurrent(mCanvas);


    }

    protected void pauseApp() {
    System.out.println("pauseApp called...");
    }

    protected void destroyApp(boolean unconditional) {
    mCanvas.stop();
    System.out.println("destroyApp called...");
    }

    }
    *********************END**********************

    ******************Mixer.java******************
    package Project;

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

    public class Mixer extends Canvas {

    Player Audioplayer, Recordplayer;
    VolumeControl vctrl;
    RateControl rctrl;
    RecordControl record;
    public ByteArrayOutputStream OutputStream;
    private ByteArrayInputStream InputStream;
    private byte [] ByteStream;
    int volume = 100;
    int rate = 100000;

    public Mixer(String title){

    System.out.println("Started...");

    }
    public void paint(Graphics g) {

    g.setColor(0x00000000);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(0x00ffffff);
    g.fillRect(0, 20, volume, 10);



    }

    public void record() {
    try {
    Recordplayer = Manager.createPlayer("capture://audio?rate=3000&bits=16");
    Recordplayer.realize();
    vctrl = (VolumeControl) Recordplayer.getControl("VolumeControl");
    vctrl.setLevel(0);
    record = (RecordControl) Recordplayer.getControl("RecordControl");
    OutputStream = new ByteArrayOutputStream();
    record.setRecordStream(OutputStream);

    Recordplayer.start();
    record.startRecord();


    System.out.println("Recording (max 20 sec.)");
    Thread.currentThread().sleep(20000);
    if(ByteStream==null){
    stoprecord();
    }
    } catch (InterruptedException ex) {
    ex.printStackTrace();
    } catch (IOException ex) {
    ex.printStackTrace();
    } catch (MediaException ex) {
    ex.printStackTrace();
    }

    }

    public void stoprecord() {
    try {
    record.commit();
    Recordplayer.close();
    System.out.println("Stopped Recording");
    ByteStream = OutputStream.toByteArray();
    } catch (IOException ex) {
    ex.printStackTrace();
    }
    }

    public void play() {
    try {
    if(ByteStream!=null){
    InputStream = new ByteArrayInputStream(ByteStream);
    Audioplayer = Manager.createPlayer(InputStream, "audio/x-wav");
    Audioplayer.realize();

    vctrl = (VolumeControl) Audioplayer.getControl("VolumeControl");
    vctrl.setLevel(volume);

    rctrl = (RateControl) Audioplayer.getControl("RateControl");
    rctrl.setRate(rate);

    Audioplayer.setLoopCount(-1);

    Audioplayer.start();
    System.out.println("Playing");
    }
    } catch (Exception e) {
    System.out.println(e.toString());
    }
    }

    public void stop() {
    try {
    Audioplayer.deallocate();
    Audioplayer.close();
    System.out.println("Stopped");
    } catch(Exception e) {}

    }

    public void keyPressed(int keyCode) {
    if(keyCode == KEY_NUM1) {
    play();
    }

    if(keyCode == KEY_NUM2) {
    stop();
    }

    if(keyCode == -4) {
    if(volume<100)
    {
    volume+=10;
    System.out.println(""+volume);
    vctrl.setLevel(volume);
    repaint();
    }
    }

    if(keyCode == -3) {
    if(volume>0)
    {
    volume-=10;
    System.out.println(""+volume);
    vctrl.setLevel(volume);
    repaint();
    }
    }

    if(keyCode == -2) {
    if(rate<300000)
    {
    rate+=10000;
    System.out.println(""+rate);
    rctrl.setRate(rate);
    }
    }

    if(keyCode == -1) {
    if(rate>0)
    {
    rate-=10000;
    System.out.println(""+rate);
    rctrl.setRate(rate);
    }
    }

    if(keyCode == KEY_POUND) {
    new Thread(new Runnable(){
    public void run() {
    try{
    record();
    }catch(Exception e){}
    }
    }).start();
    }

    if(keyCode == KEY_STAR) {
    new Thread(new Runnable(){
    public void run() {
    try{
    stoprecord();
    }catch(Exception e){}
    }
    }).start();
    }

    }

    }

    ******************END******************

  2. #2
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: Capture Audio wont work on N95 8GB

    How does it not work? Do you get an exception or what?

    Hartti

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    3

    Re: Capture Audio wont work on N95 8GB

    No exception,

    The program starts, and then does nothing..
    nothing at all.. no matter what button I push (#, *, 1 or 2)
    It should start recording when I push #, yet, it does nothing..

  4. #4
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: Capture Audio wont work on N95 8GB

    Hello GamezMaster,

    .. If Canvas is in the full screen mode and it has no CommandListener, the MIDlet triggers low-level key events from the softkeys and is thus in full control of them. ..
    Source: http://www.forum.nokia.com/document/...E0E96F2FC.html

    How about implementing a CommandListener with the Canvas object just to see if that makes any difference?

    Regards,
    r2j7
    [URL="http://library.forum.nokia.com/java"][B] >>> Java Developer's Library <<<[/B][/URL]
    [URL="https://www.developer.nokia.com/Resources/Support/Technical_support.xhtml"] [B]>>> Technical Support for Java ME development <<<[/B][/URL]
    [URL="https://publish.ovi.com/info/"][B]>>> Nokia Publish: reach millions of Nokia users worldwide through Nokia Store <<<[/B][/URL]

Similar Threads

  1. N95 8GB Uninstallation problems
    By juliand77 in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 2
    Last Post: 2007-12-07, 10:23
  2. Is the Battery Life on the N95 8GB Better than the N95?
    By brstlrovrs4life in forum General Development Questions
    Replies: 1
    Last Post: 2007-12-03, 00:04
  3. Audio capture and J2ME
    By mike.f.watson in forum Audio
    Replies: 0
    Last Post: 2005-08-05, 12:42

Posting Permissions

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