【问题标题】:unfortunately camera has stopped working不幸的是,相机已停止工作
【发布时间】:2013-01-21 06:11:03
【问题描述】:

我是安卓新手。我正在使用以下代码捕获视频:

final int REQUEST_VIDEO_CAPTURED = 1;
Long tsLong = System.currentTimeMillis() / 1000;
String ts = tsLong.toString();
String imagepath = Environment.getExternalStorageDirectory() + "/"
                    + galleryStart + "/" + FolderName + "/" + ts + ".mp4";

File file = new File(imagepath);
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,outputFileUri);
startActivityForResult(intent, REQUEST_VIDEO_CAPTURED); 

如果我没有设置路径,它的工作正常,否则它会给我错误。“不幸的是,相机已经停止工作。”我正在设置将视频保存在特定目录中的路径。

【问题讨论】:

  • 你是否在androidmanifest.xml文件中添加了对外部存储的写权限?
  • 是的,我给了它。如果我删除行 intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,outputFileUri);它工作正常。但我需要将其存储在特定目录中。

标签: android video camera


【解决方案1】:

相机应用程序不会使您成为您在Uri 中要求的目录。所以先试试吧。

String imagepath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + galleryStart + "/" + FolderName + "/" + ts + ".mp4";
File file = new File(imagepath);
  try 
  {
  if(file.exists() == false) 
    {
     file.getParentFile().mkdirs();
     file.createNewFile();
    }
  } 
  catch (IOException e) 
  {
   Log.e(TAG, "Could not create file.", e);
  }
Uri outputFileUri = Uri.fromFile(file);

希望对你有帮助!!

【讨论】:

  • 我已经有目录,视频也存储在其中。唯一的问题是它给出了错误。
  • @UttamKadam 尝试在您的视频剪辑中使用另一个扩展名instead of .mp4 try .3gp
猜你喜欢
  • 2016-03-13
  • 1970-01-01
  • 2014-01-03
  • 2016-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-15
  • 2015-08-17
相关资源
最近更新 更多