Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文件显示歌曲和点击进去看到的歌曲数量不一致。 #38

Open
houziershi opened this issue May 27, 2017 · 2 comments
Open

Comments

@houziershi
Copy link

比如:显示11首,但是,点击进入该文件夹,会发现歌曲比它多。原因,music/和music/songs 下面都有歌曲,比如music有11首。而music/songs 有3首。然后,文件夹music/显示11首,但是,点击进入会发现有14首

@houziershi
Copy link
Author

public static List getMusicFromFolder(Context context, long parent) {
List infos = new ArrayList();
final String[] proj_id = new String[]{MediaStore.Files.FileColumns._ID};
Uri uri1 = MediaStore.Files.getContentUri("external");
/* final String where_id = MediaStore.Files.FileColumns.PARENT + " =" + String.valueOf(parent)
+ " and " + WHERE;*/
StringBuilder where_id = new StringBuilder(MediaStore.Files.FileColumns.PARENT + " =" + String.valueOf(parent)
+ " and " + WHERE);
if (SharePreferencesUtils.getFilterOption(context)) {
where_id.append(" and " + MediaStore.Audio.Media.DURATION + " > " + FILTER_DURATION);
}

    Cursor cursorId = context.getContentResolver().query(uri1, proj_id, where_id.toString(), null, null);
    String[] strIDs = new String[cursorId.getCount()] ;
    if (cursorId != null) {
        int index_id = cursorId.getColumnIndex(MediaStore.Files.FileColumns._ID);
        int i = 0;
        for (cursorId.moveToFirst(); !cursorId.isAfterLast(); cursorId.moveToNext()) {
            int file_ID = cursorId.getInt(index_id);
            strIDs[i] = String.valueOf(file_ID);
            i++;
        }
    }
    if (cursorId != null) {
        cursorId.close();
    }
    List<String> parameters = new ArrayList<>();
    for (int i = 0; i < strIDs.length; i++) {
        parameters.add("?");
    }

    Cursor cursorMedia = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            null, MediaStore.Audio.Media._ID +" in (" + TextUtils.join(",", parameters) + ")",strIDs,MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
    if (cursorMedia == null) {
        return infos;
    }
    while(cursorMedia.moveToNext()) {
        MusicInfo info = new MusicInfo();
        long id = cursorMedia.getLong(cursorMedia.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
        String tilte = cursorMedia.getString(cursorMedia.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
        String album = cursorMedia.getString(cursorMedia.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
        String artist = cursorMedia.getString(cursorMedia.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
        if (artist.equals(MediaStore.UNKNOWN_STRING)) {
            artist = context.getString(R.string.unknown_name);
        }
        String url = cursorMedia.getString(cursorMedia.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
        long duration = cursorMedia.getLong(cursorMedia.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));
        long size = cursorMedia.getLong(cursorMedia.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE));
        long artistsId = cursorMedia.getInt(cursorMedia.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST_ID));
        long albumId = cursorMedia.getInt(cursorMedia.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID));
        String displayName = cursorMedia.getString(cursorMedia.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));

        info.setName(tilte);
        info.setId(id);
        info.setPath(url);
        info.setArtists(artist);
        info.setAlbum(album);
        info.setArtistsId(artistsId);
        info.setAlbumId(albumId);
        info.setSize(size);
        info.setDuration(duration);
        info.setDisplayName(displayName);
        String tag = PingYinUtil.chineneToSpell(tilte);
        if (tag.length() < 1) {
            return infos;
        }
        char c = tag.toUpperCase().charAt(0);
        if (!('A' <= c && c <= 'Z')) {
            tag = "#";
        }
        info.setFirstLetter(String.valueOf(tag.charAt(0)).toUpperCase());
        info.setPingYinName(tag);

        infos.add(info);
    }

    if (cursorMedia != null) {
        cursorMedia.close();
    }
    return infos;
}

@Cryolitia
Copy link

What's the code?Could you please give me a commit address?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants