List All Mp3 files in android

前端 未结 4 914
日久生厌
日久生厌 2021-02-03 16:28

I am developing music player in android but stuck in reading MP3 files. here is my code to read all mp3 files. but its not returing any files from device(although there are some

4条回答
  •  说谎
    说谎 (楼主)
    2021-02-03 16:42

    File[] files=new File(YOUR_DIR).listFiles();
    MediaMetadataRetriever mmr=new MediaMetadataRetriever();
    for (File file:files)
            {
                String fname=file.getName();
                String fpath=file.getAbsolutePath();
                if (file.isFile() && fname.contains("."))
                {
                    String ext=fname.substring(fname.lastIndexOf("."));
                    if (ext.equals(".mp3") || ext.equals(".MP3"))
                    {
                        mmr.setDataSource(fpath);
                        String title=mmr.extractMetadata(7);
                        String artist=mmr.extractMetadata(2);
                        String genre=mmr.extractMetadata(6);
                        String album=mmr.extractMetadata(1);
                    }
                }
    }
    mmr.release();
    

提交回复
热议问题