gpt4 book ai didi

Android 创建播放列表

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:40:44 24 4
gpt4 key购买 nike

有人知道如何在代码中将播放列表添加到 Android 吗?

我有点明白我必须将它插入到内容解析器中,但我是只需要放入歌曲 ID 还是必须放入歌曲的所有数据?

我一直在寻找示例代码,但还没有找到。

编辑:在这里找到答案是我的做法:

  public static void addToPlaylist(ContentResolver resolver, int audioId) {

String[] cols = new String[] {
"count(*)"
};
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", YOUR_PLAYLIST_ID);
Cursor cur = resolver.query(uri, cols, null, null, null);
cur.moveToFirst();
final int base = cur.getInt(0);
cur.close();
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(base + audioId));
values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audioId);
resolver.insert(uri, values);
}

public static void removeFromPlaylist(ContentResolver resolver, int audioId) {
Log.v("made it to add",""+audioId);
String[] cols = new String[] {
"count(*)"
};
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", YOUR_PLAYLIST_ID);
Cursor cur = resolver.query(uri, cols, null, null, null);
cur.moveToFirst();
final int base = cur.getInt(0);
cur.close();
ContentValues values = new ContentValues();

resolver.delete(uri, MediaStore.Audio.Playlists.Members.AUDIO_ID +" = "+audioId, null);
}

最佳答案

为了解决“未回答”的问题,我在此处粘贴了 OP 的代码:

 public static void addToPlaylist(ContentResolver resolver, int audioId) {

String[] cols = new String[] {
"count(*)"
};
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", YOUR_PLAYLIST_ID);
Cursor cur = resolver.query(uri, cols, null, null, null);
cur.moveToFirst();
final int base = cur.getInt(0);
cur.close();
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(base + audioId));
values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audioId);
resolver.insert(uri, values);
}

public static void removeFromPlaylist(ContentResolver resolver, int audioId) {
Log.v("made it to add",""+audioId);
String[] cols = new String[] {
"count(*)"
};
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", YOUR_PLAYLIST_ID);
Cursor cur = resolver.query(uri, cols, null, null, null);
cur.moveToFirst();
final int base = cur.getInt(0);
cur.close();
ContentValues values = new ContentValues();

resolver.delete(uri, MediaStore.Audio.Playlists.Members.AUDIO_ID +" = "+audioId, null);
}

关于Android 创建播放列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3182937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com