阅读量:0
要获取本地视频列表,可以使用MediaStore类来查询MediaStore.Video.Media表。以下是一个示例代码:
import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.provider.MediaStore; public class LocalVideoFetcher { public static List<String> getVideoList(Context context) { List<String> videoList = new ArrayList<>(); ContentResolver contentResolver = context.getContentResolver(); // 查询视频 String[] projection = {MediaStore.Video.Media.DATA}; Cursor cursor = contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, null, null, null); if (cursor != null) { while (cursor.moveToNext()) { String videoPath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); videoList.add(videoPath); } cursor.close(); } return videoList; } }
在调用上述方法时,需要传入一个Context对象。例如,在Activity中获取本地视频列表,可以这样调用:
List<String> videos = LocalVideoFetcher.getVideoList(this);
请注意,获取本地视频列表可能需要在AndroidManifest.xml文件中添加以下权限:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />