如何从Camera Intent获取视频并将其保存到目录?

| 是否可能有与以下类似的代码,它们对视频也是如此?
        if (resultCode == Activity.RESULT_CANCELED) {
            // camera mode was canceled.
        } else if (resultCode == Activity.RESULT_OK) {

            // Took a picture, use the downsized camera image provided by default
            Bitmap cameraPic = (Bitmap) data.getExtras().get(\"data\");
            if (cameraPic != null) {
                try {
                    savePic(cameraPic);
                } catch (Exception e) {
                    Log.e(DEBUG_TAG, \"saveAvatar() with camera image failed.\", e);
                }
            }
我想做的是能够使用Camera Intent拍摄视频并将该视频或该视频的副本保存到我的特定目录中。这是我必须剪辑的代码:
private void initTakeClip(){
    Button takeClipButton = (Button) findViewById(R.id.takeClip);
    takeClipButton.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
            String strVideoPrompt = \"Take your Video to add to your timeline!\";
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
            startActivityForResult(Intent.createChooser(cameraIntent, strVideoPrompt), TAKE_CLIP_REQUEST);
            }
    });
}
我只是不知道该怎么做,然后获取刚刚拍摄的特定视频,然后将其复制到我的sd / appname / project_name /目录中。 将已经从内存中添加的剪辑添加到目录时,获取名称/文件位置的情况也是如此:
 private void initAddClip(){
    Button addClipButton = (Button) findViewById(R.id.addClip);
    addClipButton.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
            String strAvatarPrompt = \"Choose a picture to use as your avatar!\";
            Intent pickVideo = new Intent(Intent.ACTION_PICK);
            pickVideo.setType(\"video/*\");
            startActivityForResult(Intent.createChooser(pickVideo, strAvatarPrompt), ADD_CLIP_REQUEST);

        }
    });
}
任何/所有帮助将不胜感激。     
已邀请:
首先,您需要从onActivityResult获取URI,如下所示:
private String videoPath = \"\";

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    Uri vid = data.getData();
    videoPath = getRealPathFromURI(vid);


}

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}
然后,将实际路径存储为videoPath之后,您可以使用
try {

  FileInputStream fis = openFilePath(videoPath);

  //this is where you set whatever path you want to save it as:

  File tmpFile = new File(Environment.getExternalStorageDirectory(),\"VideoFile.3gp\"); 

  //save the video to the File path
  FileOutputStream fos = new FileOutputStream(tmpFile);

  byte[] buf = new byte[1024];
  int len;
  while ((len = fis.read(buf)) > 0) {
    fos.write(buf, 0, len);
  }       
  fis.close();
  fos.close();
 } catch (IOException io_e) {
    // TODO: handle error
 }
    

要回复问题请先登录注册