Simple recording app, need help

All your problems with Audio, Video and Images.

Simple recording app, need help

Postby mcdemon » Fri Jul 17, 2009 6:57 pm

Hi,

I am trying to create a really simple audio recording app.
I followed the guide here: http://www.brighthub.com/mobile/google- ... 40735.aspx for the audio recording elements.

My app uses start and stop buttons to begin and end a recording. When I press Start, the app dies with the
"Sorry!: The application AudioRec has stopped unexpectedly. Please try again." error message. I am not sure what I could be doing wrong. My code is below, if anyone can find what I am doing wrong please let me know.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import java.io.IOException;
  2.  
  3. import java.lang.Object;
  4.  
  5.  
  6.  
  7. import android.app.Activity;
  8.  
  9. import android.media.MediaRecorder;
  10.  
  11. import android.os.Bundle;
  12.  
  13. import android.view.View;
  14.  
  15. import android.widget.Button;
  16.  
  17. import android.widget.TextView;
  18.  
  19.  
  20.  
  21. public class AudioRec extends Activity
  22.  
  23. {
  24.  
  25.         public String PATH_NAME = "/sdcard/Music/Records";
  26.  
  27.         MediaRecorder MRX = new MediaRecorder();
  28.  
  29.        
  30.  
  31.        
  32.  
  33.  
  34.  
  35.     /** Called when the activity is first created. */
  36.  
  37.     @Override
  38.  
  39.     public void onCreate(Bundle savedInstanceState) {
  40.  
  41.         super.onCreate(savedInstanceState);
  42.  
  43.         setContentView(R.layout.main);
  44.  
  45.        
  46.  
  47.         final Button button = (Button) findViewById(R.id.Button01);
  48.  
  49.         button.setOnClickListener(new View.OnClickListener()
  50.  
  51.         {
  52.  
  53.             public void onClick(View v)
  54.  
  55.             {
  56.  
  57.                 MRX.setAudioSource(MediaRecorder.AudioSource.MIC);
  58.  
  59.                 MRX.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  60.  
  61.                 MRX.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  62.  
  63.                 MRX.setOutputFile(PATH_NAME);
  64.  
  65.                
  66.  
  67.                 try {
  68.  
  69.                                 MRX.prepare();
  70.  
  71.                         } catch (IllegalStateException e) {
  72.  
  73.                                 // TODO Auto-generated catch block
  74.  
  75.                                 e.printStackTrace();
  76.  
  77.                         } catch (IOException e) {
  78.  
  79.                                 // TODO Auto-generated catch block
  80.  
  81.                                 e.printStackTrace();
  82.  
  83.                         }
  84.  
  85.                 MRX.start();
  86.  
  87.             }
  88.  
  89.         });
  90.  
  91.        
  92.  
  93.         final Button button2 = (Button) findViewById(R.id.Button02);
  94.  
  95.         button2.setOnClickListener(new View.OnClickListener()
  96.  
  97.         {
  98.  
  99.             public void onClick(View v)
  100.  
  101.             {
  102.  
  103.                 MRX.stop();
  104.  
  105.                 MRX.release();
  106.  
  107.             }
  108.  
  109.         });
  110.  
  111.        
  112.  
  113.        
  114.  
  115.     }
  116.  
  117. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Thanks
mcdemon
Freshman
Freshman
 
Posts: 4
Joined: Fri Jul 17, 2009 6:43 pm

Top

Postby TheChosen » Sat Jul 18, 2009 6:14 pm

I created a simple (and working) microphone recording tool following this tutorial: http://www.benmccann.com/dev-blog/android-audio-recording-tutorial/.

Hope it helps.
TheChosen
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Tue Jan 06, 2009 7:18 pm
Location: Germany

Postby mcdemon » Mon Jul 20, 2009 4:31 pm

It worked!!!! Thanks
mcdemon
Freshman
Freshman
 
Posts: 4
Joined: Fri Jul 17, 2009 6:43 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 18 guests