gpt4 book ai didi

java - 将捕获的视频存储在特定文件夹中并在视频 View 中播放视频

转载 作者:行者123 更新时间:2023-12-01 22:26:06 25 4
gpt4 key购买 nike

我需要一个简单的代码来存储视频并在 videoview 中显示 我需要一个简单的代码来存储视频并在 videoview 中显示。

 Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(takeVideoIntent, ACTION_TAKE_VIDEO);

我是一名新开发人员。我创建应用程序。我需要将视频存储在特定文件夹中,并在视频 View 中查看视频。

最佳答案

此代码正在运行

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (resultCode == RESULT_OK)
{
try
{
AssetFileDescriptor videoAsset = getContentResolver().openAssetFileDescriptor(data.getData(), "r");
FileInputStream fis = videoAsset.createInputStream();
File root=new File(Environment.getExternalStorageDirectory(),"/RecordVideo/"); //you can replace RecordVideo by the specific folder where you want to save the video
if (!root.exists()) {
System.out.println("No directory");
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();
}
}
}

关于java - 将捕获的视频存储在特定文件夹中并在视频 View 中播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28762016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com