当我获得每首歌曲的专辑ID时,它会重复吗?

时间:2019-01-25 06:31:36

标签: java android cursor mediastore

我用来设置相册ID 的代码:

public function destroy($id, $message = '')
{
    Debugbar::info("ok");
    Queue::push('IQueue@delete_invoice', [
        'id' => $id,
        'Class' => $this->Class,

    ]);

    return parent::destroy($id, trans("$this->class.invoice")); <--delete invoice
}

现在,当我使用以下命令在logcat中记录这些值时:

song.setAlbumID(cursor.getLong(cursor.getColumnIndexOrThrow(SONG_ALBUMID)));

我在登录日志中得到了此信息:

Log.d(TAG, "album ids: " + cursor.getLong(cursor.getColumnIndexOrThrow(SONG_ALBUMID)));

如您所见,多首歌曲具有相同的专辑ID ,当我尝试更新专辑ART 时,这给我带来了问题,因为每首ID为1的歌曲都将是更新为我选择的相册艺术

如何为每首歌曲赋予唯一ID

编辑

Song: albumids: [1]
Song: albumids: [3]
Song: albumids: [1]
Song: albumids: [4]
Song: albumids: [5]
Song: albumids: [6]
Song: albumids: [1]
Song: albumids: [1]
Song: albumids: [1]

我如何在Mediastore中插入新的ALBUM ART

final Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

final String musicsOnly = SONG_IS_MUSIC + "!=0";

    // Querying the Media DATABASE.
    cursor = resolver.query(musicUri, projection1, musicsOnly, null, null);

    try {
        if (cursor != null && cursor.moveToFirst()) {
            do {
                // Creating a SONG from the VALUES in each column.
                Song song = new Song(cursor.getLong(cursor.getColumnIndexOrThrow(SONG_ID)),
                        cursor.getString(cursor.getColumnIndexOrThrow(SONG_FILEPATH)));

                song.setTitle(cursor.getString(cursor.getColumnIndexOrThrow(SONG_TITLE)));
                song.setArtist(cursor.getString(cursor.getColumnIndexOrThrow(SONG_ARTIST)));
                song.setAlbumID(cursor.getLong(cursor.getColumnIndexOrThrow(SONG_ALBUMID)));
                song.setAlbum(cursor.getString(cursor.getColumnIndexOrThrow(SONG_ALBUM)));
                song.setDuration(cursor.getLong(cursor.getColumnIndexOrThrow(SONG_DURATION)));
                song.setYear(cursor.getInt(cursor.getColumnIndexOrThrow(SONG_YEAR)));

                // Using the previously created maps to add the current song GENRE.
                String currentGenreID = songIdToGenreIdMap.get(Long.toString(song.getId()));
                String currentGenreName = genreIdToGenreNameMap.get(currentGenreID);
                song.setGenre(currentGenreName);

                //song.add(cursor.getLong(cursor.getColumnIndexOrThrow(SONG_ALBUMID)));

                Log.d(TAG, "album id: " + cursor.getLong(cursor.getColumnIndexOrThrow(SONG_ALBUMID)));

                // Adding the Song to the global array list 'songs'.
                songs.add(song);
            } while (cursor.moveToNext());
        }

1 个答案:

答案 0 :(得分:0)

由于没有人张贴任何代码:

获取专辑的曲目

        public Cursor getAlbumTrackIds(Context context, String album_id) {
    ContentResolver cr = context.getContentResolver();
    final String _id = MediaStore.Audio.Media._ID;
    final String stralbum_id = MediaStore.Audio.Media.ALBUM_ID;
    final String track = MediaStore.Audio.Media.TRACK;
    final String[] columns = {_id};
    final String[] albumid = {album_id};
    String where = stralbum_id + "  = ?";
    return cr.query(uri, columns, where, albumid, track);
}

用AlbumArt更新媒体数据库没有意义,因为android在扫描时会注意这一点。