如何从相机意向的视频,并将其保存到一个目录?意向、相机、目录、并将其

由网友(痛彻心扉)分享简介:时有可能有code类似于做同样的视频以下?Is it possible to have code similar to the following that does the same for video?if (resultCode == Activity.RESULT_CANCELED) {// camera m...

时有可能有code类似于做同样的视频以下?

Is it possible to have code similar to the following that does the same for video?

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

我所试图做的是要能够采取使用相机意向的视频并保存录像或视频的副本到我指定的目录。这是code我必须采取剪辑:

What I am trying to do is to be able to take a video using the Camera Intent and save that video or a copy of that video to my specific directory. This is the code i have to take the clip:

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 /应用程序的名字/ PROJECT_NAME /目录。

I just don't know how to go about then getting that specific video that was just taken and then copying it into my sd/appname/project_name/ directory.

同样是添加当剪辑已经从记忆中我的目录获取名/文件位置的情况下:

The same is the case for getting the name/file location when adding a clip already from memory to my directory:

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

        }
    });
}

任何/所有帮助将是AP preciated。

Any/All help would be appreciated.

推荐答案

首先你需要做的就是从这样的onActivityResult得到URI:

First what you need to do is get the URI from the onActivityResult like this:

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存储的实际路径,那么你可以存储,使用

Then once you have the actual path stored as videoPath then you can store that using

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
 }
阅读全文

相关推荐

最新文章