×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    27

    recording sound in s40

    hi all
    i compiled a program that record and play sound and try to run it in my nokia 5310 x.e but the problem is the phone cant record when i run it in the phone and this is the expestion that shows javax.microedtion.media.mediaexception :
    Can't create player for : invalid encoding pcm ..
    so i think i need to change the encoding in this code but how . so i could try it in my phone "5310 x.e"
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package record;
    
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.control.RecordControl;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
     
    public class recordMidlet extends MIDlet implements CommandListener
    {
    private Form init = new Form("info");
    private Command rec = new Command("rec",Command.OK, 1),
    stop = new Command("stop",Command.STOP, 0),
    exit = new Command("exit",Command.EXIT, 0);
    private byte[] recordedSoundArray;
    private Player p;
    private RecordControl rc;
    private ByteArrayOutputStream output;
     
    public void startApp()
    {
    init.addCommand(rec);
    init.addCommand(stop);
    //init.addCommand(exit);
    init.setCommandListener(this);
    Display.getDisplay(this).setCurrent(init);
     
    }
     
    public void pauseApp()
    {
    }
     
    public void destroyApp(boolean unconditional)
    {
    }
     
    class dorecord extends Thread 
    {
    public void run(){
     
    	try {
     
    init.append("record voice ...\n\n");
    // Create a Player that captures live audio.
    p = Manager.createPlayer("capture://audio?encoding=MP3&rate=8000&bits=16");
    p.realize();
    // Get the RecordControl, set the record stream,
    rc = (RecordControl)p.getControl("RecordControl");
    output = new ByteArrayOutputStream();
    rc.setRecordStream(output);
    rc.startRecord();
    p.start();
     
     
     
     
    } catch (Exception ioe)
    {
    init.append(ioe.toString());
    }
    }
    }
     
    class stopplay extends Thread{
    public void run(){
     
    try
    {
    init.append("finish record... starting playback\n\n");
    rc.stopRecord();
    rc.commit();
    p.stop();
    p.close();
     
    init.append("playing...\n");
    recordedSoundArray = output.toByteArray();
    init.append("recorded sound = " +String.valueOf(recordedSoundArray.length)+"\n\n");
    ByteArrayInputStream recordedInputStream = new ByteArrayInputStream(recordedSoundArray);
    Player p2 = Manager.createPlayer(recordedInputStream,"audio/x-wav");
    p2.prefetch();
    p2.start();
    //init.append("finish playing...");
    }
    catch (Exception e) {
    init.append("stop command: "+e.toString());
     
    }
     
    }
     
    }
     
     
    public void recordaud()
    {
    	new dorecord().start();
    }
    public void stopplaying()
    {
    	new stopplay().start();
    }
     
    public void commandAction(Command com, Displayable dis)
    {
    if(com == exit)
    notifyDestroyed();
    else if(com == stop)
    {
    init.removeCommand(stop);
    init.addCommand(exit);
    stopplaying();
    }
    else if(com == rec) 
    {
     recordaud();
    }
     
    }
    }

  2. #2
    Regular Contributor
    Join Date
    Jul 2003
    Posts
    89

    Re: recording sound in s40

    HI Fevos

    You have already posted a similar query in another section, it has been answered there.
    Please avoid posting the same query in different sections.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    27

    Re: recording sound in s40

    my mistake , thank u

Similar Threads

  1. Replies: 3
    Last Post: 2008-08-03, 09:04
  2. Sound and S40
    By gutmand in forum Mobile Java General
    Replies: 6
    Last Post: 2006-06-02, 17:44
  3. Sound recording and playing
    By sasa in forum Symbian
    Replies: 0
    Last Post: 2004-10-12, 13:41
  4. Replies: 1
    Last Post: 2003-12-13, 11:17
  5. Sound example in Series 60 SDK: Recording format problem
    By jjesus in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2003-03-11, 06:15

Posting Permissions

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