ListenerMusicPlayer icon indicating copy to clipboard operation
ListenerMusicPlayer copied to clipboard

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

Open houziershi opened this issue 8 years ago • 2 comments

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

houziershi avatar May 27 '17 09:05 houziershi

public static List<MusicInfo> getMusicFromFolder(Context context, long parent) { List<MusicInfo> infos = new ArrayList<MusicInfo>(); 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;
}

houziershi avatar May 27 '17 09:05 houziershi

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

Cryolitia avatar Jul 19 '18 13:07 Cryolitia