If possible, how can I delete a playlist from MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI
, programatically?
问问题
3050 次
3 回答
7
我使用以下代码删除特定的播放列表。当然,它只需要播放列表 ID
private void deletePlaylist(String selectedplaylist)
{
// // Log.i(TAG, "deletePlaylist");
String playlistid = getPlayListId(selectedplaylist);
ContentResolver resolver = this.getContentResolver();
String where = MediaStore.Audio.Playlists._ID + "=?";
String[] whereVal = {playlistid};
resolver.delete(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, where, whereVal);
Toast toast = Toast.makeText(this,selectedplaylist + " Deleted", Toast.LENGTH_SHORT);
toast.show();
return ;
}
我创建了一个小应用程序,您可以在其中看到这一点。 https://play.google.com/store/apps/details?id=rapc.flyingdutchman.com&feature=nav_result#?t=W251bGwsMSwyLDNd
如您所见,它首先获取 playlistid。我现在只有播放列表名称。在我的代码下方获取ID。
public String getPlayListId(String playlist )
{
// read this record and get playlistid
Uri newuri =MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
final String playlistid = MediaStore.Audio.Playlists._ID;
final String playlistname = MediaStore.Audio.Playlists.NAME;
String where = MediaStore.Audio.Playlists.NAME + "=?";
String[] whereVal = {playlist};
String[] projection = {playlistid, playlistname};
ContentResolver resolver = getContentResolver();
Cursor record = resolver.query(newuri , projection, where, whereVal, null);
int recordcount = record.getCount();
String foundplaylistid = "";
if (recordcount > 0)
{
record.moveToFirst();
int idColumn = record.getColumnIndex(playlistid);
foundplaylistid = record.getString(idColumn);
record.close();
}
return foundplaylistid;
}
于 2012-11-02T10:18:32.353 回答
0
要重命名我有以下内容:
private final Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
public void renamePlaylist(Context context, String newplaylist, long playlist_id) {
ContentResolver resolver = context.getContentResolver();
ContentValues values = new ContentValues();
String where = MediaStore.Audio.Playlists._ID + " =? ";
String[] whereVal = { Long.toString(playlist_id) };
values.put(MediaStore.Audio.Playlists.NAME, newplaylist);
resolver.update(uri, values, where, whereVal);
}
于 2015-03-09T11:25:32.350 回答
0
/**
* Delete Playlist Track
*
* @param context
* @param playlistId
* @param audioId
*/
public static void deletePlaylistTrack(Context context, long playlistId, long audioId) {
ContentResolver resolver = context.getContentResolver();
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
String filter = MediaStore.Audio.Playlists.Members.AUDIO_ID + " = " + audioId;
resolver.delete(uri, filter, null);
}
/**
* Delete playlist
*
* @param context
* @param selectedplaylist
*/
public static void deletePlaylist(Context context, String selectedplaylist) {
String playlistid = getPlayListId(context, selectedplaylist);
ContentResolver resolver = context.getContentResolver();
String where = MediaStore.Audio.Playlists._ID + "=?";
String[] whereVal = {playlistid};
resolver.delete(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, where, whereVal);
}
于 2018-07-12T09:09:08.530 回答