2

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

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

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

4

1 回答 1

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

希望对你有所帮助!!

于 2013-01-21T06:40:20.623 回答