捕获视频并将其存储在特定位置而不是默认位置 [英] Capture a video and store it at a specific location rather than a default location
本文介绍了捕获视频并将其存储在特定位置而不是默认位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想捕获视频并将视频存储在默认位置以外的特定位置.
I want to capture video and store video at specific location other than default location.
我知道MediaStore有一个名为 setOutPutFile("String Location")
的方法.但是它不能正常工作.
I know there is a method with MediaStore called setOutPutFile("String Location")
.
But it is not working properly.
我已经看过许多示例并执行了,但是它仅将视频存储在默认位置.有人可以帮我解决这个问题吗?
I have seen many examples and performed but it stores video in default location only. Can someone help me solve this problem?
推荐答案
以这种方式执行:
全局声明
public static final int TAKE_PICTURE=0;
然后
Intent photoPickerIntent= new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(Intent.createChooser(photoPickerIntent,"Take Video"),TAKE_VIDEO);
通过以下方式在OnActivityResult处理中:
In OnActivityResult Handle in this way:
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK)
{
if(requestCode==TAKE_VIDEO)
{
try
{
Log.e("videopath","videopath");
AssetFileDescriptor videoAsset = getContentResolver().openAssetFileDescriptor(data.getData(), "r");
FileInputStream fis = videoAsset.createInputStream();
File root=new File(Environment.getExternalStorageDirectory(),"Directory Name");
if (!root.exists()) {
root.mkdirs();
}
File file;
file=new File(root,"android_"+System.currentTimeMillis()+".mp4" );
FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[1024];
int len;
while ((len = fis.read(buf)) > 0) {
fos.write(buf, 0, len);
}
fis.close();
fos.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
使用以下权限:
<uses-permission android:name="android.permission.RECORD_VIDEO"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
这篇关于捕获视频并将其存储在特定位置而不是默认位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文