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 = "";@OverrIDepublic 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); 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,len); } fis.close(); fos.close(); } catch (IOException io_e) { // Todo: handle error }总结
以上是内存溢出为你收集整理的android – 如何从相机Intent获取视频并将其保存到目录?全部内容,希望文章能够帮你解决android – 如何从相机Intent获取视频并将其保存到目录?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)