画像ボタンを押し続けている限り音を録音するシンプルなアプリを作っていますが、録音が終わった後、Androidデバイスでファイルが見つかりません。
コード:
public class MainActivity extends Activity {
MediaRecorder recorder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//AUDIO RECORDER
recorder = new MediaRecorder();
recorder.reset();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
String externalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
recorder.setOutputFile(externalStoragePath + "/easyvoicenotepad/test.3gp");
}
else
{
String storagePath = Environment.getRootDirectory().getAbsolutePath();
recorder.setOutputFile(storagePath + "/easyvoicenotepad/test.3gp");
}
//IMAGE BUTTON ONTOUCHLISTENER
final ImageButton recBtn = (ImageButton) findViewById(R.id.recButton);
recBtn.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
recBtn.setImageResource(R.drawable.record_btn_pressed);
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if (event.getAction() == MotionEvent.ACTION_UP)
{
recBtn.setImageResource(R.drawable.record_btn);
try {
recorder.prepare();
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return true;
}
});
} //END OF ONCREATE
権限:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.STORAGE" />