4

다음과 비슷한 코드를 비디오에도 적용 할 수 있습니까? 내가 뭘하려고 오전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); 
       } 
      } 

내 특정 디렉토리에 그 비디오 또는 비디오의 사본을 카메라 의도를 사용하여 비디오를 촬영하고 저장 할 수있다.

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/프로젝트 이름/디렉토리로 복사 한 후 바로 찍은 특정 비디오를 받고 이동하는 방법을 모른다 : 이것은 내가 클립을해야 코드 .

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

     } 
    }); 
} 

모든/모든 도움을 주시면 감사하겠습니다 :

같은 내 디렉토리 메모리에서 이미 클립을 추가 할 때 이름/파일 위치를 가져 오는 경우입니다.

답변

7

먼저 당신이해야 할 것은이 같은하여 onActivityResult에서 URI를 얻을 수 있습니다 : 당신이 실제 경로는 다음 저장할 수 있습니다 videoPath로 저장 한 후 다음

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

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 
} 
+0

감사를 사용하여 Seantron .. – Kalpesh

+2

FileInputStream fis = openFilePath (videoPath); 이 진술에 나는 혼란스럽고 읽을 수가 없다 ...... 나를 도울 수 있니? – Kalpesh

관련 문제