【问题标题】:camera problems in androidandroid中的相机问题
【发布时间】:2011-09-29 11:30:13
【问题描述】:

在我的应用程序中,我正在捕获视频并将其保存到 sdcard。自 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)

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

【问题讨论】:

    标签: android android-camera android-version


    【解决方案1】:

    如果您不使用 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);
    

    【讨论】:

    • thanks.i 运行您的代码,从 8 开始的 api 级别工作正常。但低于 api 级别 8 工作但我捕获视频 20 秒它播放空白视频 20 秒。请帮帮我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-29
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多