0

デフォルトのカメラアプリを使用して、インテントを使用して録画/撮影を処理しようとしていますが、デフォルトのコードが正しく機能しないようです。http://developer.android.com/guide/topics/media/camera.html

このコードはアイス クリーム サンドイッチでは機能しますが、ジンジャーブレッド (2.3) では機能します。ビデオを録画しようとすると画像/プレビューがフリーズし、ビデオを撮り直そうとするとクラッシュします。

スタックトレースから、ビデオ形式をサポートしているように見えますが、ドキュメントで明示的にサポートしています...

どんな助けや考えも大歓迎です。:)

私のコード:

public class CameraInterface {
    public static final int MEDIA_TYPE_IMAGE = 1;
    public static final int MEDIA_TYPE_VIDEO = 2;

    public static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
    public static final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 200;

    private static Uri fileUri;

    public static void takePicture(Activity activity){
        // create Intent to take a picture and return control to the calling application
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name

        // start the image capture Intent
        activity.startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    }


    public static void takeVideo(Activity activity){
        //create new Intent
        Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

        fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);  // create a file to save the video
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);  // set the image file name

        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high

        // start the Video Capture Intent
        activity.startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);
    }


    /** Create a file Uri for saving an image or video */
    private static Uri getOutputMediaFileUri(int type){
          return Uri.fromFile(getOutputMediaFile(type));
    }

    /** Create a File for saving an image or video */
    private static File getOutputMediaFile(int type){
        // To be safe, you should check that the SDCard is mounted
        // using Environment.getExternalStorageState() before doing this.

        File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
                  Environment.DIRECTORY_PICTURES), "MyCameraApp");
        // This location works best if you want the created images to be shared
        // between applications and persist after your app has been uninstalled.

        // Create the storage directory if it does not exist
        if (! mediaStorageDir.exists()){
            if (! mediaStorageDir.mkdirs()){
                Log.d("MyCameraApp", "failed to create directory");
                return null;
            }
        }

        // Create a media file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        File mediaFile;
        if (type == MEDIA_TYPE_IMAGE){
            mediaFile = new File(mediaStorageDir.getPath() + File.separator +
            "IMG_"+ timeStamp + ".jpg");
        } else if(type == MEDIA_TYPE_VIDEO) {
            mediaFile = new File(mediaStorageDir.getPath() + File.separator +
            "VID_"+ timeStamp + ".mp4");
        } else {
            return null;
        }

        return mediaFile;
    }
}

スタックトレース:

 E/videocamera(17373)    Couldn't view video file   ///mnt/sdcard/Pictures/MyCameraApp/VID_20120410_151830.mp4              
 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 }            
 E/videocamera(17373)       at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java    1409)           
 E/videocamera(17373)       at android.app.Instrumentation.execStartActivity(Instrumentation.java   1379)           
 E/videocamera(17373)       at android.app.Activity.startActivityForResult(Activity.java    2827)           
 E/videocamera(17373)       at android.app.Activity.startActivity(Activity.java 2933)           
 E/videocamera(17373)       at com.android.camera.VideoCamera.startPlayVideoActivity(VideoCamera.java   488)            
 E/videocamera(17373)       at com.android.camera.VideoCamera.onClick(VideoCamera.java  501)            
 E/videocamera(17373)       at android.view.View.performClick(View.java 2485)           
 E/videocamera(17373)       at android.view.View$PerformClick.run(View.java 9080)           
 E/videocamera(17373)       at android.os.Handler.handleCallback(Handler.java   587)            
 E/videocamera(17373)       at android.os.Handler.dispatchMessage(Handler.java  92)         
 E/videocamera(17373)       at android.os.Looper.loop(Looper.java   130)            
 E/videocamera(17373)       at android.app.ActivityThread.main(ActivityThread.java  3683)           
 E/videocamera(17373)       at java.lang.reflect.Method.invokeNative(Native Method)             
 E/videocamera(17373)       at java.lang.reflect.Method.invoke(Method.java  507)            
 E/videocamera(17373)       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java   839)            
 E/videocamera(17373)       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java  597)            
 E/videocamera(17373)       at dalvik.system.NativeStart.main(Native Method)                
 W/dalvikvm(17373)   threadid=1  thread exiting with uncaught exception (group=0x40015560)              
 E/AndroidRuntime(17373)     FATAL EXCEPTION     main               
 E/AndroidRuntime(17373)     java.lang.IllegalArgumentException  Unknown URL file   ///mnt/sdcard/Pictures/MyCameraApp/VID_20120410_151830.mp4          
 E/AndroidRuntime(17373)        at android.content.ContentResolver.delete(ContentResolver.java  688)            
 E/AndroidRuntime(17373)        at com.android.camera.VideoCamera.deleteCurrentVideo(VideoCamera.java   1090)           
 E/AndroidRuntime(17373)        at com.android.camera.VideoCamera.onClick(VideoCamera.java  497)            
 E/AndroidRuntime(17373)        at android.view.View.performClick(View.java 2485)           
 E/AndroidRuntime(17373)        at android.view.View$PerformClick.run(View.java 9080)           
 E/AndroidRuntime(17373)        at android.os.Handler.handleCallback(Handler.java   587)            
 E/AndroidRuntime(17373)        at android.os.Handler.dispatchMessage(Handler.java  92)         
 E/AndroidRuntime(17373)        at android.os.Looper.loop(Looper.java   130)            
 E/AndroidRuntime(17373)        at android.app.ActivityThread.main(ActivityThread.java  3683)           
 E/AndroidRuntime(17373)        at java.lang.reflect.Method.invokeNative(Native Method)             
 E/AndroidRuntime(17373)        at java.lang.reflect.Method.invoke(Method.java  507)            
 E/AndroidRuntime(17373)        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java   839)            
 E/AndroidRuntime(17373)        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java  597)            
 E/AndroidRuntime(17373)        at dalvik.system.NativeStart.main(Native Method)                
4

1 に答える 1