I am trying to make a gallery app which shows videos from internal storage. I had been able to access videos from external storage before. You can find the code below.
private void loadVideos() {
new Thread() {
@Override
public void run() {
super.run();
String[] projection = {MediaStore.Video.Media._ID, MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.DURATION};
This part I can access the external storage and certain folder which I want.
Cursor cursor = getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection,
MediaStore.Video.Media.DATA +" like ? ",
new String[]{"%Moody%"},
null);
if (cursor != null) {
int idColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID);
int titleColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
int durationColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION);
while (cursor.moveToNext()) {
long id = cursor.getLong(idColumn);
String title = cursor.getString(titleColumn);
int duration = cursor.getInt(durationColumn);
Uri data = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id);
String duration_formatted;
int sec = (duration / 1000) % 60;
int min = (duration / (1000 * 60)) % 60;
int hrs = duration / (1000 * 60 * 60);
if (hrs == 0) {
duration_formatted = String.valueOf(min).concat(":".concat(String.format(Locale.UK, "%02d", sec)));
} else {
duration_formatted = String.valueOf(hrs).concat(":".concat(String.format(Locale.UK, "%02d", min).concat(":".concat(String.format(Locale.UK, "%02d", sec)))));
}
videosList.add(new ModelVideo(id, data, title, duration_formatted));
runOnUiThread(new Runnable() {
@Override
public void run() {
adapterVideoList.notifyItemInserted(videosList.size() - 1);
}
});
}
}
}
}.start();
}
question from:
https://stackoverflow.com/questions/65541069/how-to-reach-video-folder-path-from-internal-storage 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…