安卓相机的问题
在我的应用程序中,我正在捕获视频并将其保存到 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不使用 CamcorderProfile,则可以使用下面的代码,因为 CamcorderProfile 是自 API 级别 8 以来引入的。
You can use the code below if you are not using CamcorderProfile because CamcorderProfile has been introduced since API level 8.