Audio Recorder from MIC

All your problems with Audio, Video and Images.

Audio Recorder from MIC

Postby sudheer1437 » Fri Aug 28, 2009 4:55 pm

Hi Guys,
I am working on a task where i need to record the audio which is taken from MIC.
and save in either local drive or sdcard. I implemented the following code.

But i m unable load the sdcard.

I used the basic commands given in developer.android.com to create sdcard image and load.
but i couldn succeed.
Plz help me out in doing this.


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.sample.recorder;
  3.  
  4.  
  5.  
  6. import android.app.Activity;
  7.  
  8. import android.media.MediaPlayer;
  9.  
  10. import android.media.MediaRecorder;
  11.  
  12. import android.os.Bundle;
  13.  
  14. import android.view.View;
  15.  
  16. import android.view.View.OnClickListener;
  17.  
  18. import android.widget.Button;
  19.  
  20. import android.widget.Toast;
  21.  
  22.  
  23.  
  24. public class Test extends Activity implements OnClickListener
  25.  
  26. {
  27.  
  28.        
  29.  
  30.        
  31.  
  32.         @Override
  33.  
  34.         public void onCreate(Bundle icici)
  35.  
  36.         {
  37.  
  38.                 super.onCreate(icici);
  39.  
  40.                 setContentView(R.layout.record);
  41.  
  42.                
  43.  
  44.                 Button stop = (Button) findViewById(R.id.stop);
  45.  
  46.                 stop.setOnClickListener(this);
  47.  
  48.                 Button rec = (Button) findViewById(R.id.rec);
  49.  
  50.                 rec.setOnClickListener(this);
  51.  
  52.                 Button play = (Button) findViewById(R.id.play);
  53.  
  54.                 play.setOnClickListener(this);
  55.  
  56.                
  57.  
  58.         }
  59.  
  60.  
  61.  
  62.         @Override
  63.  
  64.         public void onClick(View v)
  65.  
  66.         {
  67.  
  68.                
  69.  
  70.                
  71.  
  72.                 int id = v.getId();
  73.  
  74.                
  75.  
  76.                 String PATH_NAME = "/sdcard/Music/Records";
  77.  
  78.             MediaRecorder mRecorder = new MediaRecorder();
  79.  
  80.            
  81.  
  82.                 MediaPlayer mp;
  83.  
  84.                 mp = MediaPlayer.create(getBaseContext(), R.raw.test_cbr);
  85.  
  86.                
  87.  
  88.             if(id == R.id.rec)
  89.  
  90.                 {
  91.  
  92.                 mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  93.  
  94.                 mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  95.  
  96.                 mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  97.  
  98.                 mRecorder.setOutputFile(PATH_NAME);
  99.  
  100.                
  101.  
  102.                 try
  103.  
  104.                 {
  105.  
  106.                         mRecorder.prepare();
  107.  
  108.                 }
  109.  
  110.                 catch(Exception e)
  111.  
  112.                 {
  113.  
  114.                        
  115.  
  116.                 }
  117.  
  118.                 mRecorder.start();
  119.  
  120.                
  121.  
  122.                
  123.  
  124.                 }
  125.  
  126.                 else if(id == R.id.play)
  127.  
  128.                 {
  129.  
  130.                     mp.start();
  131.  
  132.                 }
  133.  
  134.                 else if(id == R.id.stop)
  135.  
  136.                 {
  137.  
  138.                         mp.stop();
  139.  
  140.                         mp.release();
  141.  
  142.                         mRecorder.stop();
  143.  
  144.                         Toast.makeText(getBaseContext(),"cello...",Toast.LENGTH_SHORT);
  145.  
  146.                         mRecorder.release();
  147.  
  148.                 }
  149.  
  150.         }
  151.  
  152. }
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
sudheer1437
Experienced Developer
Experienced Developer
 
Posts: 79
Joined: Sat Aug 08, 2009 7:42 am
Location: India

Top

Postby sudheer1437 » Fri Aug 28, 2009 5:06 pm

I am starting the emulator by using the following command:

emulator @my_avd -sdcard sdcard2.img

(where sdcard2.img is the sdcard image file) This is working.
But when i try to upload a music file test.3gp by the command:
adb push test.3gp /sdcard

it is showing error

wad to do..
where i went wrong..???
Plz help me...
sudheer1437
Experienced Developer
Experienced Developer
 
Posts: 79
Joined: Sat Aug 08, 2009 7:42 am
Location: India

Postby sudheer1437 » Fri Aug 28, 2009 9:10 pm

Thanks everybody..
I got the solution.
sudheer1437
Experienced Developer
Experienced Developer
 
Posts: 79
Joined: Sat Aug 08, 2009 7:42 am
Location: India

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 17 guests