Android Create Playlist

后端 未结 4 1524
暗喜
暗喜 2020-12-23 10:58

Anyone know how to add playlists to Android in code?

I kind of get that I have to insert it into the content resolver but do I have to just put the song id in or do

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 11:21

    To answer Jaroslav Záruba comment, the code is better with the PLAY_ORDER of added track set as follows:

    cur.moveToLast();
    final int base = cur.getInt(cur.getColumnIndex(Playlists.Members.PLAY_ORDER));
    cur.close();
    ContentValues values = new ContentValues();
    values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, 
          Integer.valueOf(base + 1));
    

    Two major things change : We use the last element of the playlist (cur.moveToLast()) and we add 1 to its PLAY_ORDER value to determine the new track's PLAY_ORDER. The point is to have successive tracks in the playlist.

    You can also add 10 for example so that you can insert tracks before or after your new track. I also changed the way we get the id of track. Indeed we don't want to have any problem getting wrong data so we specify the column we want.

提交回复
热议问题