mRecorder.prepare();
mRecorder.start();
Thread auto_stop=new Thread(new Runnable()
{
@Override
public void run() {
try {
Thread.sleep(30000);
if(WavAudioRecorder.flag)
{
mRecorder.stop();
mRecorder.reset();
btnControl.setText("Start");
return ;
}
} catch (InterruptedException e) {
//e.printStackTrace();
}
}
});
auto_stop.start();
我正在尝试制作一个记录 30 秒并停止的记录器应用程序。我正在使用上述代码来停止记录器。记录 30 秒后应用程序崩溃。如何解决崩溃部分?我用于启动和停止的代码在此链接中。有没有其他方法可以在 30 秒后自动停止录音机
04-23 09:53:34.955: E/AndroidRuntime(4278): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
04-23 09:53:34.955: E/AndroidRuntime(4278): at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4746)
04-23 09:53:34.955: E/AndroidRuntime(4278): at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:823)
04-23 09:53:34.955: E/AndroidRuntime(4278): at android.view.View.requestLayout(View.java:15468)
04-23 09:53:34.955: E/AndroidRuntime(4278): at android.view.View.requestLayout(View.java:15468)
04-23 09:53:34.955: E/AndroidRuntime(4278): at android.view.View.requestLayout(View.java:15468)
04-23 09:53:34.955: E/AndroidRuntime(4278): at android.view.View.requestLayout(View.java:15468)
04-23 09:53:34.955: E/AndroidRuntime(4278): at android.view.View.requestLayout(View.java:15468)
04-23 09:53:34.955: E/AndroidRuntime(4278): at android.widget.TextView.checkForRelayout(TextView.java:6313)
04-23 09:53:34.955: E/AndroidRuntime(4278): at android.widget.TextView.setText(TextView.java:3567)
04-23 09:53:34.955: E/AndroidRuntime(4278): at android.widget.TextView.setText(TextView.java:3425)
04-23 09:53:34.955: E/AndroidRuntime(4278): at android.widget.TextView.setText(TextView.java:3400)
04-23 09:53:34.955: E/AndroidRuntime(4278): at com.example.androidwaverecorder.MainActivity$1$1.run(MainActivity.java:53)
04-23 09:53:34.955: E/AndroidRuntime(4278): at java.lang.Thread.run(Thread.java:856)