android中的相机问题

时间:2011-09-29 11:30:13

标签: android android-camera android-version

在我的应用程序中,我正在捕获视频并将其保存到SD卡。我的下面的代码工作正常,因为api级别8.但如果我在api级别8(从7)下面运行我的应用程序它会崩溃。它说

java.lang.NoClassDefFoundError:android.media.CamcorderProfile

如何在支持所有版本/级别的情况下运行我的应用程序? CamcorderProfile 类的替代方法是什么。

我的代码是

  ..............
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);  // NoClassDefFoundError: android.media.CamcorderProfile error occur here.
    mediaRecorder.setProfile(camcorderProfile_HQ);
    mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
    mediaRecorder.setMaxDuration(60000); 
    mediaRecorder.setMaxFileSize(5000000); 

    .....................

请帮帮我。提前谢谢。

我的Logcat详细信息:

09-29 16:44:06.971: ERROR/AndroidRuntime(7800): java.lang.NoClassDefFoundError: android.media.CamcorderProfile
09-29 16:44:06.971: ERROR/AndroidRuntime(7800):     at com.exercise.AndroidVideoCapture.AndroidVideoCapture.initMediaRecorder(AndroidVideoCapture.java:84)
09-29 16:44:06.971: ERROR/AndroidRuntime(7800):     at com.exercise.AndroidVideoCapture.AndroidVideoCapture.onCreate(AndroidVideoCapture.java:28)
09-29 16:44:06.971: ERROR/AndroidRuntime(7800):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-29 16:44:06.971: ERROR/AndroidRuntime(7800):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
09-29 16:44:06.971: ERROR/AndroidRuntime(7800):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
09-29 16:44:06.971: ERROR/AndroidRuntime(7800):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
09-29 16:44:06.971: ERROR/AndroidRuntime(7800):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
09-29 16:44:06.971: ERROR/AndroidRuntime(7800):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 16:44:06.971: ERROR/AndroidRuntime(7800):     at android.os.Looper.loop(Looper.java:123)
09-29 16:44:06.971: ERROR/AndroidRuntime(7800):     at android.app.ActivityThread.main(ActivityThread.java:4363)

............................

1 个答案:

答案 0 :(得分:3)

如果您未使用 CamcorderProfile ,则可以使用以下代码,因为自API级别8以来已引入 CamcorderProfile

mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);