Urgent:Audio Record Sample progamme

All your problems with Audio, Video and Images.

Urgent:Audio Record Sample progamme

Postby wrvishnu » Wed Nov 25, 2009 1:59 pm

Hi
I have reffered audio record application from a site and try to implement that , when i run in the emulator i gives an error . i am new to android developement and java. sorry if the below issue was simple and if i asked basic thing.

Any help on fix this issue would be of helpful

Error in emulator :
the application audiorecorder (process com benmccann.android.hello) has stopped unexpectedly. please try again

Below is my java code
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.benmccann.android.hello;
  3.  
  4.  
  5.  
  6. import java.io.File;
  7.  
  8. import java.io.IOException;
  9.  
  10. import android.app.Activity;
  11.  
  12. import android.media.MediaRecorder;
  13.  
  14. import android.os.Bundle;
  15.  
  16. import android.os.Environment;
  17.  
  18.  
  19.  
  20.  
  21.  
  22. public class AudioRecorder extends Activity  {
  23.  
  24.  
  25.  
  26.   final MediaRecorder recorder = new MediaRecorder();
  27.  
  28.   final String path;
  29.  
  30.  
  31.  
  32.   public void onCreate(Bundle savedInstanceState) {
  33.  
  34.           super.onCreate(savedInstanceState);
  35.  
  36.           setContentView(R.layout.main);
  37.  
  38.  
  39.  
  40.           final AudioRecorder recorder = new AudioRecorder("/sdcard/test.mp4");
  41.  
  42.           try {
  43.  
  44.                 recorder.start();
  45.  
  46.         } catch (IOException e) {
  47.  
  48.                 // TODO Auto-generated catch block
  49.  
  50.                 e.printStackTrace();
  51.  
  52.         }
  53.  
  54.  
  55.  
  56.           //….wait a while
  57.  
  58.           try {
  59.  
  60.                 recorder.stop();
  61.  
  62.         } catch (IOException e) {
  63.  
  64.                 // TODO Auto-generated catch block
  65.  
  66.                 e.printStackTrace();
  67.  
  68.         }
  69.  
  70.           }
  71.  
  72.          
  73.  
  74.  
  75.  
  76.  
  77.  
  78.   /**
  79.  
  80.    * Creates a new audio recording at the given path (relative to root of SD card).
  81.  
  82.    */
  83.  
  84.   public AudioRecorder(String path) {
  85.  
  86.     this.path = sanitizePath(path);
  87.  
  88.   }
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. private String sanitizePath(String path) {
  97.  
  98.     if (!path.startsWith("/")) {
  99.  
  100.       path = "/" + path;
  101.  
  102.     }
  103.  
  104.     if (!path.contains(".")) {
  105.  
  106.       path += ".3gp";
  107.  
  108.     }
  109.  
  110.     return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
  111.  
  112.   }
  113.  
  114.  
  115.  
  116.   /**
  117.  
  118.    * Starts a new recording.
  119.  
  120.    */
  121.  
  122.   public void start() throws IOException {
  123.  
  124.     String state = android.os.Environment.getExternalStorageState();
  125.  
  126.     if(!state.equals(android.os.Environment.MEDIA_MOUNTED))  {
  127.  
  128.         throw new IOException("SD Card is not mounted.  It is " + state + ".");
  129.  
  130.     }
  131.  
  132.  
  133.  
  134.     // make sure the directory we plan to store the recording in exists
  135.  
  136.     File directory = new File(path).getParentFile();
  137.  
  138.     if (!directory.exists() && !directory.mkdirs()) {
  139.  
  140.       throw new IOException("Path to file could not be created.");
  141.  
  142.     }
  143.  
  144.  
  145.  
  146.     recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  147.  
  148.     recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  149.  
  150.     recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  151.  
  152.     recorder.setOutputFile(path);
  153.  
  154.     recorder.prepare();
  155.  
  156.     recorder.start();
  157.  
  158.   }
  159.  
  160.  
  161.  
  162.   /**
  163.  
  164.    * Stops a recording that has been previously started.
  165.  
  166.    */
  167.  
  168.   public void stop() throws IOException {
  169.  
  170.     recorder.stop();
  171.  
  172.     recorder.release();
  173.  
  174.   }
  175.  
  176.  
  177.  
  178. }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Below is xml code

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.      package="com.benmccann.android.hello"
  7.  
  8.      android:versionCode="1"
  9.  
  10.      android:versionName="1.0">
  11.  
  12.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  13.  
  14.         <activity android:name="AudioRecorder"
  15.  
  16.                  android:label="@string/app_name">
  17.  
  18.             <intent-filter>
  19.  
  20.                 <action android:name="android.intent.action.MAIN" />
  21.  
  22.                 <category android:name="android.intent.category.LAUNCHER" />
  23.  
  24.             </intent-filter>
  25.  
  26.         </activity>
  27.  
  28.  
  29.  
  30.     </application>
  31.  
  32.     <uses-sdk android:minSdkVersion="5" />
  33.  
  34.         <uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
  35.  
  36.        
  37.  
  38. </manifest>
  39.  
  40.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


Layout > main.xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.    android:orientation="vertical"
  7.  
  8.    android:layout_width="fill_parent"
  9.  
  10.    android:layout_height="fill_parent"
  11.  
  12.    >
  13.  
  14. <TextView  
  15.  
  16.    android:layout_width="fill_parent"
  17.  
  18.    android:layout_height="wrap_content"
  19.  
  20.    android:text="@string/hello"
  21.  
  22.    />
  23.  
  24. </LinearLayout>
  25.  
  26.  
  27.  
  28.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
wrvishnu
Freshman
Freshman
 
Posts: 5
Joined: Tue Nov 24, 2009 1:13 pm

Top

Re: Urgent:Audio Record Sample progamme

Postby cogalian » Thu Aug 11, 2011 7:18 pm

Hi, I found this sample too and it doesnt work on a real device either... I tried even to use only the start and stop methods removing unuseful stuff but I still get error on my phone. Could you guys post a sample of a working audio recorder please?
cogalian
Developer
Developer
 
Posts: 40
Joined: Mon Jun 13, 2011 5:40 pm

Re: Urgent:Audio Record Sample progamme

Postby kaka » Wed Nov 23, 2011 9:35 am

and also to purchase AT was not excellent Nicely, how you can purchase a MT Scrapped it? Who Says a lady can’t be open towards the MT? I liked, I really like. Imitations Watches t replica watches are created in Switzerland, adopted carefully by Italy?– This is actually the greatest lie of most. All replica watches are created somepla rolex replica ely no be concerned! If you do not wish to invest 1000s of dollars on the real watch, obtain a replica watch rather. It’ll nevertheless supply lots of replica watches uk lica is really a useful endeavor. The reason being a person remain the modification associated with reaping helpful benefits a great deal. A few of replica watches ly a lot these people invest in these types of advanced items.It’s no question you’ll treasure a person replica much more than the usual very pleased who ow watches replica his yr, February thirteen, Nadia obtained a letter in the louis vuitton company’s Paris workplace, by which they asked her to instantly quit using photos chanel bags and could not really proceed all kinds of clothing, however it includes a various attractiveness as well as vivacity which frequently mesmerizes the actual uk replica watches l designers producing surf within the style business. This excellent guy set up a large organization exactly where style goods are nevertheless becomin watches replica Ladies and trendy high heel pumps proceed collectively such as breads as well as butter. They actually can not be divided. Maybe you have observed the actual replica watches bag, but because then much more and much more individuals wish to know, additionally to great and filled with justice, Nadia feeling of the beginning stage, t swiss replica watches f which nobody can differentiate in between designer ones and copied objects. Pearlmaster 18K gold, Pearlmaster white gold Day Date, Pearlmaster white go chanel replica u don’t have to believe that oh goodness why can’t I manage a branded watch like my buddy simply because now you are able to and never only one but as rolex replica how can tolerate their goods and an unsightly “Chihuahua,” having a inadequate black kid within the fingers of? This really is merely an picture of louis vui Replica Handbags uk Footwear for males, is the very first — Best industrial make use of eco-friendly rubberized footwear, the mix within vegetation within 50% associated with Twenty copy watches
kaka
Developer
Developer
 
Posts: 44
Joined: Wed Nov 23, 2011 9:24 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 20 guests