开发者

camera problems in android

开发者 https://www.devze.com 2023-04-09 01:44 出处:网络
in my app i am capturing video and save it to sdcard. my below co开发者_运维知识库de is working fine since api level 8. but if i run my app below api level 8(from 7) it get crashed. it says

in my app i am capturing video and save it to sdcard. my below co开发者_运维知识库de 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)

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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号