{"id":1441,"date":"2022-08-30T15:16:33","date_gmt":"2022-08-30T15:16:33","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/16\/camcorder-activity-not-working-with-example-code-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:33","modified_gmt":"2022-08-30T15:16:33","slug":"camcorder-activity-not-working-with-example-code-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/camcorder-activity-not-working-with-example-code-collection-of-common-programming-errors\/","title":{"rendered":"Camcorder activity not working with example code-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to use the default camera app to handle recording\/taking pictures using intents but can&#8217;t seem to get the default code to work properly. http:\/\/developer.android.com\/guide\/topics\/media\/camera.html<\/p>\n<p>This code works on Ice Cream sandwich but on Gingerbread (2.3) When trying to record video the image\/preview is frozen and when I attempt to retake video it crashes.<\/p>\n<p>From the stacktrace it seems like it does support the video format but it explicitly supports it in the documentation&#8230;<\/p>\n<p>Any help or thoughts would be greatly appreciated. \ud83d\ude42<\/p>\n<p>My code:<\/p>\n<pre><code>public class CameraInterface {\n    public static final int MEDIA_TYPE_IMAGE = 1;\n    public static final int MEDIA_TYPE_VIDEO = 2;\n\n    public static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;\n    public static final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 200;\n\n    private static Uri fileUri;\n\n    public static void takePicture(Activity activity){\n        \/\/ create Intent to take a picture and return control to the calling application\n        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);\n\n        fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); \/\/ create a file to save the image\n        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); \/\/ set the image file name\n\n        \/\/ start the image capture Intent\n        activity.startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);\n    }\n\n\n    public static void takeVideo(Activity activity){\n        \/\/create new Intent\n        Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);\n\n        fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);  \/\/ create a file to save the video\n        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);  \/\/ set the image file name\n\n        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); \/\/ set the video image quality to high\n\n        \/\/ start the Video Capture Intent\n        activity.startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);\n    }\n\n\n    \/** Create a file Uri for saving an image or video *\/\n    private static Uri getOutputMediaFileUri(int type){\n          return Uri.fromFile(getOutputMediaFile(type));\n    }\n\n    \/** Create a File for saving an image or video *\/\n    private static File getOutputMediaFile(int type){\n        \/\/ To be safe, you should check that the SDCard is mounted\n        \/\/ using Environment.getExternalStorageState() before doing this.\n\n        File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(\n                  Environment.DIRECTORY_PICTURES), \"MyCameraApp\");\n        \/\/ This location works best if you want the created images to be shared\n        \/\/ between applications and persist after your app has been uninstalled.\n\n        \/\/ Create the storage directory if it does not exist\n        if (! mediaStorageDir.exists()){\n            if (! mediaStorageDir.mkdirs()){\n                Log.d(\"MyCameraApp\", \"failed to create directory\");\n                return null;\n            }\n        }\n\n        \/\/ Create a media file name\n        String timeStamp = new SimpleDateFormat(\"yyyyMMdd_HHmmss\").format(new Date());\n        File mediaFile;\n        if (type == MEDIA_TYPE_IMAGE){\n            mediaFile = new File(mediaStorageDir.getPath() + File.separator +\n            \"IMG_\"+ timeStamp + \".jpg\");\n        } else if(type == MEDIA_TYPE_VIDEO) {\n            mediaFile = new File(mediaStorageDir.getPath() + File.separator +\n            \"VID_\"+ timeStamp + \".mp4\");\n        } else {\n            return null;\n        }\n\n        return mediaFile;\n    }\n}\n<\/code><\/pre>\n<p>Stack trace:<\/p>\n<pre><code> E\/videocamera(17373)    Couldn't view video file   \/\/\/mnt\/sdcard\/Pictures\/MyCameraApp\/VID_20120410_151830.mp4              \n E\/videocamera(17373)    android.content.ActivityNotFoundException   No Activity found to handle Intent { act=android.intent.action.VIEW dat=file   \/\/\/mnt\/sdcard\/Pictures\/MyCameraApp\/VID_20120410_151830.mp4 }            \n E\/videocamera(17373)       at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java    1409)           \n E\/videocamera(17373)       at android.app.Instrumentation.execStartActivity(Instrumentation.java   1379)           \n E\/videocamera(17373)       at android.app.Activity.startActivityForResult(Activity.java    2827)           \n E\/videocamera(17373)       at android.app.Activity.startActivity(Activity.java 2933)           \n E\/videocamera(17373)       at com.android.camera.VideoCamera.startPlayVideoActivity(VideoCamera.java   488)            \n E\/videocamera(17373)       at com.android.camera.VideoCamera.onClick(VideoCamera.java  501)            \n E\/videocamera(17373)       at android.view.View.performClick(View.java 2485)           \n E\/videocamera(17373)       at android.view.View$PerformClick.run(View.java 9080)           \n E\/videocamera(17373)       at android.os.Handler.handleCallback(Handler.java   587)            \n E\/videocamera(17373)       at android.os.Handler.dispatchMessage(Handler.java  92)         \n E\/videocamera(17373)       at android.os.Looper.loop(Looper.java   130)            \n E\/videocamera(17373)       at android.app.ActivityThread.main(ActivityThread.java  3683)           \n E\/videocamera(17373)       at java.lang.reflect.Method.invokeNative(Native Method)             \n E\/videocamera(17373)       at java.lang.reflect.Method.invoke(Method.java  507)            \n E\/videocamera(17373)       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java   839)            \n E\/videocamera(17373)       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java  597)            \n E\/videocamera(17373)       at dalvik.system.NativeStart.main(Native Method)                \n W\/dalvikvm(17373)   threadid=1  thread exiting with uncaught exception (group=0x40015560)              \n E\/AndroidRuntime(17373)     FATAL EXCEPTION     main               \n E\/AndroidRuntime(17373)     java.lang.IllegalArgumentException  Unknown URL file   \/\/\/mnt\/sdcard\/Pictures\/MyCameraApp\/VID_20120410_151830.mp4          \n E\/AndroidRuntime(17373)        at android.content.ContentResolver.delete(ContentResolver.java  688)            \n E\/AndroidRuntime(17373)        at com.android.camera.VideoCamera.deleteCurrentVideo(VideoCamera.java   1090)           \n E\/AndroidRuntime(17373)        at com.android.camera.VideoCamera.onClick(VideoCamera.java  497)            \n E\/AndroidRuntime(17373)        at android.view.View.performClick(View.java 2485)           \n E\/AndroidRuntime(17373)        at android.view.View$PerformClick.run(View.java 9080)           \n E\/AndroidRuntime(17373)        at android.os.Handler.handleCallback(Handler.java   587)            \n E\/AndroidRuntime(17373)        at android.os.Handler.dispatchMessage(Handler.java  92)         \n E\/AndroidRuntime(17373)        at android.os.Looper.loop(Looper.java   130)            \n E\/AndroidRuntime(17373)        at android.app.ActivityThread.main(ActivityThread.java  3683)           \n E\/AndroidRuntime(17373)        at java.lang.reflect.Method.invokeNative(Native Method)             \n E\/AndroidRuntime(17373)        at java.lang.reflect.Method.invoke(Method.java  507)            \n E\/AndroidRuntime(17373)        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java   839)            \n E\/AndroidRuntime(17373)        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java  597)            \n E\/AndroidRuntime(17373)        at dalvik.system.NativeStart.main(Native Method)                \n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-16 20:53:28. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to use the default camera app to handle recording\/taking pictures using intents but can&#8217;t seem to get the default code to work properly. http:\/\/developer.android.com\/guide\/topics\/media\/camera.html This code works on Ice Cream sandwich but on Gingerbread (2.3) When trying to record video the image\/preview is frozen and when I attempt to retake video it crashes. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1441","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1441"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1441\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}