gpt4 book ai didi

Android mediarecorder 停止失败

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:07:05 26 4
gpt4 key购买 nike

我遇到了一个非常奇怪的行为:有时我的 mediarecorder 崩溃并出现错误“停止失败”,有时它工作正常。是我的错还是系统的bug?我不知道哪里出了问题。

private void stopRecording(){
ticker.cancel();
ticker.purge();

recorder.stop();

startBtn.setText("Start");
recordInProcess = false;

markList = locWriteTask.getMarkArray();

mCamera.lock();
recorder.release();
}

private void startRecording(){

startBtn.setText("Stop");

recordInProcess = true;

recorder = new MediaRecorder();

mCamera.unlock();
recorder.setCamera(mCamera);

recorder.setPreviewDisplay(mSurfaceHolder.getSurface());
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setMaxDuration((int) 10000000);
recorder.setVideoSize(320, 240);
recorder.setVideoFrameRate(15);
recorder.setOutputFile(FULL_PATH_TO_LOCAL_FILE + counter + MP4);

try{
recorder.prepare();
} catch (Exception e){
finish();
}

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);

ticker = new Timer();
locWriteTask = new WriteTimeLocationTimerTask(ll);
ticker.schedule(locWriteTask, 0, DELAY);

recorder.start();
}

最佳答案

您可能会在 MediaRecorder.stop() 方法中捕获 RuntimeException。

例子:

MediaRecorder mRecorder = new MediaRecorder();
File mFile = new File("The output file's absolutePath");

... //config the mRecorder
mRecorder.setOutputFile(mFile.getAbsolutePath());

... //prepare() ...
mRecorder.start();

try {
mRecorder.stop();
} catch(RuntimeException e) {
mFile.delete(); //you must delete the outputfile when the recorder stop failed.
} finally {
mRecorder.release();
mRecorder = null;
}

关于Android mediarecorder 停止失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10147563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com