安卓相机的问题

发布于 2024-12-07 02:09:02 字数 2332 浏览 10 评论 0原文

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

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

in my app i am capturing video and save it to sdcard. my below code is working fine since api level 8. but if i run my app below api level 8(from 7) it get crashed. it says

java.lang.NoClassDefFoundError: android.media.CamcorderProfile.

how to run my app with the all version/level supported? what is the alternative for CamcorderProfile class.

my code is

  ..............
    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); 

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

please help me. Thanks in advance.

my Logcat details:

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)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半寸时光 2024-12-14 02:09:02

如果您不使用 CamcorderProfile,则可以使用下面的代码,因为 CamcorderProfile 是自 API 级别 8 以来引入的。

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);

You can use the code below if you are not using CamcorderProfile because CamcorderProfile has been introduced since API level 8.

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文