2017-07-14 13 views
0

マイコード:音声記録プログラム

public class MainActivity extends AppCompatActivity { 

    private Button mRecordBtn; 
    private TextView mRecordLabel; 

    private MediaRecorder mRecorder; 

    private String mFileName = null; 

    private static final String LOG_TAG = "Record_log"; 

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

     mRecordLabel = (TextView) findViewById(R.id.recordLabel); 
     mRecordBtn = (Button) findViewById(R.id.recordBtn); 

     mFileName = Environment.getExternalStorageDirectory().getAbsolutePath(); 
     mFileName = "/recorded_audio.3gp"; 


     mRecordBtn.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View v, MotionEvent motionEvent) { 

       if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){ 

        startRecording(); 
        mRecordLabel.setText("Recording in Progress"); 


       } 
       else if (motionEvent.getAction() == MotionEvent.ACTION_UP){ 
        stopRecording(); 
        mRecordLabel.setText("Recording Stopped"); 

       } 
       return false; 
      } 
     }); 

    } 

    private void startRecording() { 
     mRecorder = new MediaRecorder(); 
     mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
     mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
     mRecorder.setOutputFile(mFileName); 
     mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 

     try { 
      mRecorder.prepare(); 
     } catch (IOException e) { 
      Log.e(LOG_TAG, "prepare() failed"); 
     } 

     mRecorder.start(); //I am getting a bug on this line 
    } 

    private void stopRecording() { 
     mRecorder.stop(); 
     mRecorder.release(); 
     mRecorder = null; 


    } 
} 

私は私のサムスンギャラクシーS7エッジでこのコードを実行しただけでなく、Androidのスタジオアプリのクラッシュによって与えられたnexxus 7エミュレータで。私はすべてのコードを掲載しています。ボタンを押すとクラッシュします。録音するために押して保持するようにして、録音を停止するために解放する

+1

エラーログを送信してください。 – ZeekHuge

+0

[不幸にもMyAppが停止しました。どうすれば解決できますか?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) –

+0

アプリがクラッシュするような質問はおそらくほとんどのAndroidの質問)その1つの複製として – Markaos

答えて

0

問題が音声を録音する許可であるかどうか確認してください。

+0

ええ、私は両方のことを確認した私はそれを実行したアプリケーションは、 –

関連する問題