录音机Android

时间:2013-03-22 12:04:51

标签: android eclipse audio mediarecorder android-mediarecorder

我正在录制声音,但是当我尝试录制声音时,模拟器停止了,因为它要求我插入SD卡。我该怎么办?我不能没有SD卡吗?

谢谢!

   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();
            }
        }

    }

2 个答案:

答案 0 :(得分:1)

您可以选择通过mksdcard命令创建SD卡,并将其与amulator相关联。

答案 1 :(得分:0)

请看这个功能:

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().

您可以决定存储文件的位置。

也看看这个例子。 http://androidfreakers.blogspot.co.il/2011/09/using-mediarecorder.html