1

我正在做一个应用程序来录制声音,但是当我尝试录制声音时,模拟器停止了,因为它要求我插入 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();
            }
        }

    }
4

2 回答 2

1

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

于 2013-03-22T12:19:42.350 回答
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

于 2013-03-22T12:14:57.947 回答