内部存储文件夹(0)不显示任何文件

nimxete2  于 2021-07-06  发布在  Java
关注(0)|答案(2)|浏览(462)

我正在开发一个视频播放器应用程序,我正在显示视频文件夹和视频,这是工作正常,但内部存储文件夹“0”没有显示任何文件,但我有大约15个视频文件,但其他文件夹工作正常。
这是我的密码

private ArrayList<Videos_Models>LoadVideos(Context context, String FolderName){
        ArrayList<Videos_Models> TempList = new ArrayList<>();

        Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;

        String [] projection = {
                MediaStore.Video.Media._ID,
                MediaStore.Video.Media.DATA,
                MediaStore.Video.Media.TITLE,
                MediaStore.Video.Media.SIZE,
                MediaStore.Video.Media.DATE_ADDED,
                MediaStore.Video.Media.DURATION,
                MediaStore.Video.Media.DISPLAY_NAME,
                MediaStore.Video.Media.BUCKET_DISPLAY_NAME

        };

        String selection = MediaStore.Video.Media.DATA+" Like?";
        String  []selectionArgs = new String[]{"%" + FolderName +"%"};
        Cursor cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);

        if (cursor!= null){
            while (cursor.moveToNext()){

                try {
                String id =cursor.getString(0);
                String path =cursor.getString(1);
                String title =cursor.getString(2);
                String size =cursor.getString(3);
                String dateAdded =cursor.getString(4);
                String duration =cursor.getString(5);
                String fileName =cursor.getString(6);
                String bucket_name =cursor.getString(7);

                int durationa = Integer.parseInt(duration);

                String duration_formet;
                int sec = (durationa/1000)%60;
                int min = (durationa/(1000*60))%60;
                int hours = durationa/(1000*60*60);

                if (hours == 0){
                    duration_formet = String.valueOf(min).concat(":" .concat(String.format(Locale.UK, "%02d",sec)));
                }else {
                    duration_formet = String.valueOf(hours).concat(":" .concat(String.format(Locale.UK, "%02d",min).concat(":" .concat(String.format(Locale.UK, "%02d",sec)))));

                }

                Videos_Models videoFiles = new Videos_Models(id, path, title,fileName,size, dateAdded,duration_formet);

                Log.d("path", path);

               if (FolderName.endsWith(bucket_name)){
                  TempList.add(videoFiles);
               }

            }catch (Exception e){

                }

            }
            cursor.close();
        }
        return TempList;
    }

我做错了什么?如何解决这个问题?

jvlzgdj9

jvlzgdj91#

既然你需要的是内部存储器,你能试着更换你的吗 Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;uri = MediaStore.Video.Media.INTERNAL_CONTENT_URI; 看有什么不同

ig9co6j1

ig9co6j12#

你能检查一下你是否有这个权限吗 <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" /> 在你的清单文件里。

相关问题