我开发了一款平板电脑的应用程序,使用前置摄像头进行视频录制,我在三星galaxy s(android 2.3.6)上测试了该应用程序,它运行良好,但当我在htc传单上运行相同的代码(android 2.3。 4)当mediarecorder.start()执行时它会卡住。可能是原因:)
public boolean startRecording() throws IOException{
try {
camera.unlock();
//mediaRecorder.release();
mediaRecorder = new MediaRecorder();
mediaRecorder.reset();
mediaRecorder.setCamera(camera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mediaRecorder.setMaxDuration(maxDurationInMs);
File externalStorage = Environment.getRootDirectory();
File r=getDir("jaris", MODE_WORLD_WRITEABLE);
Toast.makeText(getApplicationContext(), r.getAbsolutePath().toString()+" ", Toast.LENGTH_LONG).show();
File tempFile = new File(r.getAbsolutePath(),"kkcadsga.3gp");
tempFile.createNewFile();
mediaRecorder.setOutputFile(tempFile.getPath());
mediaRecorder.setVideoFrameRate(videoFramesPerSecond);
mediaRecorder.setVideoSize(surfaceView.getWidth(), surfaceView.getHeight());
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
// mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
//mediaRecorder.setCamera(camera);
mediaRecorder.setMaxFileSize(maxFileSizeInBytes);
Toast.makeText(getApplicationContext(), "file stored1 ", Toast.LENGTH_LONG).show();
//camera.unlock();
try{
mediaRecorder.prepare();
}catch (Exception e) {
// TODO: handle exception
Toast.makeText(getApplicationContext(), "status "+ e.getMessage().toString(), Toast.LENGTH_LONG).show();
}
Toast.makeText(getApplicationContext(), "file stored4444 ", Toast.LENGTH_LONG).show();
b1.setOnClickListener(new OnClickListener(){
public void onClick(View save) {
//camera.lock();
try{ mediaRecorder.start();
}catch (Exception e) {
// TODO: handle exception
Toast.makeText(getApplicationContext(), e.getMessage().toString(), Toast.LENGTH_LONG).show();
}
b1.setVisibility(Button.GONE);
b2.setVisibility(Button.VISIBLE);
Toast.makeText(getApplicationContext(), "sto ", Toast.LENGTH_LONG).show();
}
});
// for(int k=0; k < 4000 ; k++){
// for(int n=0; k < 4000 ; k++){
//
// }
// }
OnClickListener i = null;
b2.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
mediaRecorder.stop();
mediaRecorder.reset();
camera.lock();
Toast.makeText(getApplicationContext(), "stopped ", Toast.LENGTH_LONG).show();
b2.setVisibility(Button.GONE);
b1.setVisibility(Button.VISIBLE);
}
});
return true;
} catch (IllegalStateException e) {
}
return false;
}