简体   繁体   English

视频意图后,相机应用程序崩溃,但图片意图正常吗?

[英]Camera app crashes after video intent, but picture intent works fine?

I am using the camera intent to capture both still images and videos using the default camera app. 我正在使用相机意图使用默认相机应用程序同时捕捉静止图像和视频。 The method for taking a picture and the one for taking a video are very similar. 拍摄照片的方法和拍摄视频的方法非常相似。 The picture one works great, it saves the photo to the temporary file I supply the path to in the intent. 图片效果很好,它将照片保存到我打算提供的路径的临时文件中。 However the video does not work. 但是视频不起作用。

The video intent opens the camera app as normal, and then I record m video, and all seems fine, but when I finish recording or reach one of the limits the camera app just crashes. 视频意图会正常打开相机应用程序,然后录制m个视频,一切似乎都很好,但是当我完成录制或达到限制之一时,相机应用程序就会崩溃。

This is my code from my activity for calling the camera app: 这是我调用照相机应用程序时的活动代码:

private void takeVideo()
{
       Intent videoIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);

       File tempFolder = new File(Environment.getExternalStorageDirectory(), "MediaTemp");
       tempFolder.mkdirs(); 
       File video = new File(tempFolder, "vid.tmp");
       Uri uriSavedVideo = Uri.fromFile(video);
       videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedVideo);
       videoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 60);
       videoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
       videoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long)(16*1024*1024));

       this.startActivityForResult(videoIntent, 2);
}

private void takePicture()
{
       Intent pictureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

       File tempFolder = new File(Environment.getExternalStorageDirectory(), "MediaTemp");
       tempFolder.mkdirs(); 
       File image = new File(tempFolder, "pic.tmp");
       Uri uriSavedImage = Uri.fromFile(image);
       pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);

       this.startActivityForResult(pictureIntent, 1);
}

I do not think that the problem is in the OnActivityResult method because the app that crashes is the camera app and not my own app, so the problem it encounters must happen before my app gets control back in OnActivityResult. 我不认为问题出在OnActivityResult方法中,因为崩溃的应用是相机应用而不是我自己的应用,因此它遇到的问题必须在我的应用重新控制OnActivityResult之前发生。 But I cannot understand what is causing this crash.. Can anyone offer some insight into this? 但是我不明白是什么原因导致此崩溃。.有人可以对此提供一些见解吗?

I have not worked with the Android camera but you might want to have a look at how CommonsWare solved these problems in his library: https://github.com/commonsguy/cwac-camera 我没有使用Android相机,但是您可能想看看CommonsWare如何在他的库中解决这些问题: https : //github.com/commonsguy/cwac-camera

From the github page: 从github页面:

CWAC-Camera is an effort to standardize that "ton of code" and hide it behind a scalable API. CWAC-Camera致力于标准化“大量代码”并将其隐藏在可扩展的API之后。 Here, "scalable" means "simple things are simple, but complex things may be a bit complex". 在这里,“可伸缩”的意思是“简单的事物很简单,但是复杂的事物可能有点复杂”。

Credits to https://stackoverflow.com/users/115145/commonsware 归功于https://stackoverflow.com/users/115145/commonsware

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM