gpt4 book ai didi

android - 如何列出android中特定文件夹中的所有视频

转载 作者:行者123 更新时间:2023-11-29 00:26:16 25 4
gpt4 key购买 nike

我正在开发视频录制应用程序。我想列出我将存储在特定文件夹中的视频。通过以下代码,我可以从移动设备上获取所有视频。但我需要列出来自特定文件夹的视频文件夹。任何人都可以指导我吗?提前致谢

public class VideoListActivity extends Activity {
private Cursor videocursor;
private int video_column_index;
ListView videolist;
int count;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_list);
init_phone_video_grid();
}

private void init_phone_video_grid() {
System.gc();
String[] proj = { MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.SIZE };
videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
proj, null, null, null);
count = videocursor.getCount();

videolist = (ListView) findViewById(R.id.listView1);
videolist.setAdapter(new VideoAdapter(getApplicationContext()));
videolist.setOnItemClickListener(videogridlistener);
}

private OnItemClickListener videogridlistener = new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,
long id) {
System.gc();
video_column_index = videocursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
videocursor.moveToPosition(position);
String filename = videocursor.getString(video_column_index);
Intent intent = new Intent(VideoListActivity.this, Viewvideo.class);
intent.putExtra("videofilename", filename);

startActivity(intent);
}
};

public class VideoAdapter extends BaseAdapter {
private Context vContext;

public VideoAdapter(Context c) {
vContext = c;
}

public int getCount() {
return count;
}

public Object getItem(int position) {
return position;
}

public long getItemId(int position) {
return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
System.gc();
TextView tv = new TextView(vContext.getApplicationContext());
String id = null;
if (convertView == null) {
video_column_index = videocursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
videocursor.moveToPosition(position);
id = videocursor.getString(video_column_index);
video_column_index = videocursor
.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
videocursor.moveToPosition(position);
id += " Size(KB):" + videocursor.getString(video_column_index);


ImageView iv = new ImageView(vContext);
ContentResolver crThumb = getContentResolver();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, position, MediaStore.Video.Thumbnails.MICRO_KIND, options);
iv.setImageBitmap(curThumb);

tv.setText(id);

} else
tv = (TextView) convertView;
return tv;
}
}
}

最佳答案

试试下面的代码:

public static ArrayList<File> getListFiles(File parentDir) {
ArrayList<File> inFiles = new ArrayList<File>();
File[] files;
files = parentDir.listFiles();
if (files != null) {
for (File file : files) {
if (file.getName().endsWith(".mp4") ||
file.getName().endsWith(".gif")) {
if (!inFiles.contains(file)) inFiles.add(file);

if (!inFiles.contains(file)) inFiles.add(file);
}
}
}
return inFiles;
}

使用:

private static final String WHATSAPP_STATUSES_LOCATION =  
"/storage/emulated/0/yourfoldername";


getListFiles(new File(WHATSAPP_STATUSES_LOCATION));

关于android - 如何列出android中特定文件夹中的所有视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19178459/

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