Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
86 views
in Technique[技术] by (71.8m points)

java - How to reach video folder path from internal storage?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...