Android: MediaRecorder.start() runetimException 模糊错误
Android: MediaRecorder.start() runetimException vague error
我只是想创建一个麦克风 class,它是允许其他代码开始和停止录音的外观。但是我总是收到以下错误:
Caused by: java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.start(Native Method)
at kwedt.afasie_app.service.Microphone.Record(Microphone.java:41)
at kwedt.afasie_app.NamingActivity.recordAudio(NamingActivity.java:69)
at kwedt.afasie_app.NamingActivity.commence(NamingActivity.java:51)
at kwedt.afasie_app.AphasiaTestActivity.setSubtest(AphasiaTestActivity.java:143)
at kwedt.afasie_app.AphasiaTestActivity.menuSelect(AphasiaTestActivity.java:251)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
这是我的 class:
public class Microphone
{
private MediaRecorder recorder;
public Microphone()
{
recorder = new MediaRecorder();
init();
}
private void init()
{
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);;
}
public void Record(Context context, String path) throws DomainException
{
File file = new File(context.getFilesDir(), path + Calendar.getInstance()
.get(Calendar.SECOND)); //save recording under current time
recorder.setOutputFile(file.getAbsolutePath());
try
{
recorder.prepare();
}
catch (IOException e)
{
throw new DomainException(e,"Could not prepare microphone." + e.toString());
}
recorder.start();
}
public void Stop()
{
recorder.stop();
recorder.reset();
recorder.release();
}
}
我几乎在整个万维网上搜索了一个答案,但找不到。
我还请求了录制音频的权限,并在我的模拟器中看到该应用程序具有使用麦克风的权限。
模拟器没有麦克风...您必须在真实设备上使用它。
我只是想创建一个麦克风 class,它是允许其他代码开始和停止录音的外观。但是我总是收到以下错误:
Caused by: java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.start(Native Method)
at kwedt.afasie_app.service.Microphone.Record(Microphone.java:41)
at kwedt.afasie_app.NamingActivity.recordAudio(NamingActivity.java:69)
at kwedt.afasie_app.NamingActivity.commence(NamingActivity.java:51)
at kwedt.afasie_app.AphasiaTestActivity.setSubtest(AphasiaTestActivity.java:143)
at kwedt.afasie_app.AphasiaTestActivity.menuSelect(AphasiaTestActivity.java:251)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
这是我的 class:
public class Microphone
{
private MediaRecorder recorder;
public Microphone()
{
recorder = new MediaRecorder();
init();
}
private void init()
{
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);;
}
public void Record(Context context, String path) throws DomainException
{
File file = new File(context.getFilesDir(), path + Calendar.getInstance()
.get(Calendar.SECOND)); //save recording under current time
recorder.setOutputFile(file.getAbsolutePath());
try
{
recorder.prepare();
}
catch (IOException e)
{
throw new DomainException(e,"Could not prepare microphone." + e.toString());
}
recorder.start();
}
public void Stop()
{
recorder.stop();
recorder.reset();
recorder.release();
}
}
我几乎在整个万维网上搜索了一个答案,但找不到。 我还请求了录制音频的权限,并在我的模拟器中看到该应用程序具有使用麦克风的权限。
模拟器没有麦克风...您必须在真实设备上使用它。