Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor prashantpersistent's Avatar
    Join Date
    May 2008
    Posts
    68
    hi all

    i m getting bad quality of recording for following code of audio recorder, need some help.

    Code:
     /*
      * RecordVideoCanvas.java
      * Created on Aug 20, 2008, 10:00:20 AM
      /
    
    package audio;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import javax.microedition.io.file.FileConnection;
    import javax.microedition.lcdui.Alert;
    import javax.microedition.lcdui.AlertType;
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    import javax.microedition.media.control.RateControl;
    import javax.microedition.media.control.RecordControl;
    import javax.microedition.media.control.VideoControl;
    import javax.microedition.media.control.VolumeControl;
    
    public class RecordAudioCanvas extends Canvas implements CommandListener{
        FileConnection fc;
        RecordMidlet rmidlet;
        Player player,player3;
        RecordControl reorder;
        VideoControl video;
        CameraThread cthread ;
        RecordThread rthread;
        ViewAudio vaudio;
        ByteArrayOutputStream bout;
        byte[] recordArray;
        private  int videoHeight  ;
        private  int videoWidth ;
        private  int SPACE = 5;
        private Command cmdRecord;
        private Command cmdStop;
        private Command cmdExit;
        private Command cmdPlay; 
           
        public RecordAudioCanvas(RecordMidlet midlet) {
            rthread = new RecordThread();
            cthread = new CameraThread();
            vaudio =  new ViewAudio();
            videoHeight  = getHeight();
            videoWidth   = getWidth();
            rmidlet = midlet;
            cmdRecord = new Command("Record", Command.SCREEN, 0);
            cmdStop   = new Command("Stop", Command.STOP, 0);
            cmdExit   = new Command("Exit", Command.EXIT, 0);
            cmdPlay   = new Command("Play", Command.SCREEN, 1);
            addCommand(cmdPlay);
            addCommand(cmdStop);
            addCommand(cmdRecord);
            addCommand(cmdExit);
            setCommandListener(this);
            cthread.start();
        }
        
        protected void paint(Graphics g) {
            g.setColor(0x005945);
            g.fillRect(0, 0, videoWidth, videoHeight);
            g.setColor(0xffffff);
            g.drawLine(SPACE, SPACE, SPACE, videoHeight - SPACE );
            g.drawLine(SPACE, SPACE, videoWidth - SPACE, SPACE );
        }
    
        public void commandAction(Command cmd, Displayable arg1) {
     
            if(cmd == cmdRecord){
                if(player == null){
                    cthread.start();
                    rthread.start();
                }else
                    rthread.start();
            }
            
            if(cmd == cmdExit){
                rmidlet.destroyApp(true);
            }
            
            if(cmd == cmdPlay){
                 vaudio.start();
            }
            
            if(cmd == cmdStop){
                if(reorder != null)
                    stopRecord();
            }
        }
        
        private void startAudio(){
            try {
                String message = System.getProperty("supports.recording");
                System.out.println(""+message);
                InputStream is = getClass().getResourceAsStream("/test-wav.wav");
                player = Manager.createPlayer(is, "audio/x-wav");
                player.setLoopCount(1);
                player.realize();
                VolumeControl volume = (VolumeControl) player.getControl("VolumeControl");
                volume.setLevel(20);
                player.start();
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (MediaException ex) {
                ex.printStackTrace();
            }
        }
        
        class CameraThread extends Thread{
            public void run(){
                startAudio();
            }
        }
        
        class RecordThread extends Thread{
            public void run(){
                recordAudio();
            }
        }
                
        private void recordAudio(){
            
            reorder = (RecordControl) player.getControl("RecordControl");
            if(reorder == null){
                Alert alert = new Alert("recording","recording not supported" , null, null);
                alert.setString("not supported");
                alert.setTimeout(3000);
                Display.getDisplay(rmidlet).setCurrent(alert);
            }
            System.out.println("record state"+reorder);
            bout = new ByteArrayOutputStream();
            reorder.setRecordStream(bout);
            reorder.startRecord();
            try {
                Thread.currentThread().sleep(20000);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
            try {
                reorder.stopRecord();
                reorder.commit();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            
        }
        
        private void stopRecord(){
            
            try {
                reorder.stopRecord();
                reorder.commit();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        
        class ViewAudio extends Thread{
            
            public void run(){
                viewAudio();
            }
            
            private void viewAudio(){
               
                if(player!= null)
                    try {
                    player.stop();
                    player.deallocate();
                } catch (MediaException ex) {
                    ex.printStackTrace();
                }
                Alert alert = new Alert("message", bout.toString(), null, null);
                alert.setTimeout(Alert.FOREVER);
                Display.getDisplay(rmidlet).setCurrent(alert);
                ByteArrayInputStream bais = new ByteArrayInputStream(bout.toByteArray());
    
                try {
                    try {
                        System.out.println("supported type is" + System.getProperty("audio.encodings"));
                        System.out.println("video type is"+player.getContentType());
                        player3 = Manager.createPlayer(bais,"audio/x-wav");
                        
                        
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    } catch (MediaException ex) {
                        ex.printStackTrace();
                    }
                    player3.setLoopCount(1);
                   
                    
                    player3.realize();
                    player3.prefetch();
                    RateControl rate = (RateControl)player3.getControl("RateControl");
                        rate.setRate(200000);
                } catch (MediaException ex) {
                    ex.printStackTrace();
                }
                           
                try {
                    player3.start();
                    
                } catch (MediaException ex) {
                    ex.printStackTrace();
                }
            }
            
        }
       
    }

  2. #2
    Nokia Developer Moderator r2j7's Avatar
    Join Date
    Aug 2007
    Posts
    1,595
    Hello prashantpersistent,

    which device this app is set to? It depends also on whether the target device supports the recording formats.

    Some MIME types:

    http://wiki.forum.nokia.com/index.php/MMAPI

    MIDP: Mobile Media API Support In Nokia Devices:

    http://www.forum.nokia.com/info/sw.n..._0_en.xls.html

    Regards,
    r2j7

Similar Threads

  1. Audio playing over RTP on 6600 and 6620.
    By ravinathwani in forum Symbian Media (Closed)
    Replies: 5
    Last Post: 2008-05-24, 09:49
  2. Problem recording audio
    By bps4484 in forum Python
    Replies: 1
    Last Post: 2006-08-08, 15:47
  3. Audio input streaming problem on Series 60 v2.6 phones (6680,6630)
    By andrew.hayes in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2006-01-20, 14:30
  4. noise recorded durng sampling audio on 6600
    By alphanet in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2005-11-18, 14:58
  5. Audio Playing on phone : Query
    By sshuhangi in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2003-07-04, 06:30

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved