我有活動與MediaRecorder它在Android 2.3.6上的作品。現在我在Samsung Galaxy S2(4.044)和mRecorder.start()上嘗試使用所有CamcorderProfiles的RuntimeException。它的作品只與480P,但視頻損壞的線。 我試過這個解決方案。開始()/損壞的視頻Android MediaRecorder RuntimeException
Camera.Parameters params = camera.getParameters();
params.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
params.set("cam_mode",1);
camera.setParameters(params);
但它不起作用。其他解決方案?
手機閃過android,可能是這個問題?
我的代碼
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (camera == null) {
camera = Camera.open();
}
Camera.Parameters params = camera.getParameters();
params.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
params.set("cam_mode",1);
camera.setParameters(params);
if (camera != null) {
try {
camera.setPreviewDisplay(holder);
camera.startPreview();
} catch (IOException e) {
e.printStackTrace();
}
} else {
Toast.makeText(getApplicationContext(), "Camera not available.", Toast.LENGTH_LONG).show();
finish();
}
}
public void startRecording() throws IOException {
camera.stopPreview();
prepareRecord();
recordButton.setImageResource(R.drawable.record_button_stop);
startRecord();
}
public void prepareRecord() throws IllegalStateException, IOException {
if (camera == null) {
camera = Camera.open();
}
if (mRecorder == null) {
mRecorder = new MediaRecorder();
}
camera.lock();
camera.unlock();
mRecorder.setCamera(camera);
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
CamcorderProfile cProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
mRecorder.setProfile(cProfile);
mRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mRecorder.setOutputFile(pathName + "/" + fileName + ".mp4");
mRecorder.prepare();
}
public void startRecord() {
if (recording == false) {
mRecorder.start();
recording = true;
}
}
logcat的
02-21 01:49:38.505: E/AndroidRuntime(4210): FATAL EXCEPTION: main
02-21 01:49:38.505: E/AndroidRuntime(4210): java.lang.RuntimeException: start failed.
02-21 01:49:38.505: E/AndroidRuntime(4210): at android.media.MediaRecorder.native_start(Native Method)
02-21 01:49:38.505: E/AndroidRuntime(4210): at android.media.MediaRecorder.start(MediaRecorder.java:704)
02-21 01:49:38.505: E/AndroidRuntime(4210): at com.olos.videogpsrecorder.VideoRecorderActivity.startRecord(VideoRecorderActivity.java:401)
02-21 01:49:38.505: E/AndroidRuntime(4210): at com.olos.videogpsrecorder.VideoRecorderActivity.startRecording(VideoRecorderActivity.java:343)
02-21 01:49:38.505: E/AndroidRuntime(4210): at com.olos.videogpsrecorder.VideoRecorderActivity$1.onClick(VideoRecorderActivity.java:129)
02-21 01:49:38.505: E/AndroidRuntime(4210): at android.view.View.performClick(View.java:3511)
02-21 01:49:38.505: E/AndroidRuntime(4210): at android.view.View$PerformClick.run(View.java:14105)
02-21 01:49:38.505: E/AndroidRuntime(4210): at android.os.Handler.handleCallback(Handler.java:605)
02-21 01:49:38.505: E/AndroidRuntime(4210): at android.os.Handler.dispatchMessage(Handler.java:92)
02-21 01:49:38.505: E/AndroidRuntime(4210): at android.os.Looper.loop(Looper.java:137)
02-21 01:49:38.505: E/AndroidRuntime(4210): at android.app.ActivityThread.main(ActivityThread.java:4575)
02-21 01:49:38.505: E/AndroidRuntime(4210): at java.lang.reflect.Method.invokeNative(Native Method)
02-21 01:49:38.505: E/AndroidRuntime(4210): at java.lang.reflect.Method.invoke(Method.java:511)
02-21 01:49:38.505: E/AndroidRuntime(4210): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-21 01:49:38.505: E/AndroidRuntime(4210): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-21 01:49:38.505: E/AndroidRuntime(4210): at dalvik.system.NativeStart.main(Native Method)
試着把mRecorder.start();一行後prepere – 2013-03-13 08:09:30
它沒有幫助。 – 2013-03-13 09:46:55
我會嘗試另一個4.0.4手機。也許這是特定手機或特定品牌的問題。 – 2013-03-13 12:54:31