Alex23
Alex23

Reputation: 15

Audio Recorder Android

I'm doing a aplication to recorder the sound, but when I try to record the sound,the emulator is stopped because it ask me to insert an SD card. What I have to do? I couldn't do without an SD card ?

Thank you!

   package proiektua.proiektua;


import java.io.FileDescriptor;

import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;

import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;


public class MainActivity extends Activity  {

        int peticion = 1;
        Uri url1;
        private int STATE_CONFIGURE;
        private int mState = STATE_CONFIGURE;


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }

        public void grabar(View v) {
            Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
            startActivityForResult(intent, peticion);}

            public void setOutputFile(FileDescriptor fd) {
                    switch (mState) {
                case STATE_RECORD:
                        throw new RuntimeException("setOutputFile cannot be called while recording!");

                    case STATE_RELEASED:
                        throw new RuntimeException("setOutputFile called on an already released recorder!");
                    default:
                        break;
                }
        }

        public void reproducir(View v) {
            MediaPlayer mediaPlayer = MediaPlayer.create(this, url1);
            mediaPlayer.start();
        }

        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (resultCode == RESULT_OK && requestCode == peticion) {
                url1 = data.getData();
            }
        }

    }

Upvotes: 1

Views: 1164

Answers (2)

Deepak Bala
Deepak Bala

Reputation: 11185

You have the option to create an SDCard through the mksdcard command and associate it with the amulator.

Upvotes: 1

Gilad
Gilad

Reputation: 6595

please look at this function:

public void setOutputFile (FileDescriptor fd)

Added in API level 3
Pass in the file descriptor of the file to be written. Call this after setOutputFormat() but before prepare().

You can decide where to store the file.

also look at this example. http://androidfreakers.blogspot.co.il/2011/09/using-mediarecorder.html

Upvotes: 0

Related Questions