如何从内部存储访问视频文件夹路径?

z9ju0rcb  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(270)

我试图使一个画廊应用程序,显示从内部存储的视频。我以前可以从外部存储访问视频。你可以找到下面的代码。

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};

这部分我可以访问外部存储器和我想要的某个文件夹。

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();
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题