如何在Android中从MediaStore.Audio.Playlists删除播放列表
如果可能,如何以编程方式从MediaStore.Audio.Playlists.EXTERNAL\u CONTENT\u URI中删除播放列表 我使用以下代码删除特定的播放列表。当然,它只需要播放列表id如何在Android中从MediaStore.Audio.Playlists删除播放列表,android,playlist,mediastore,Android,Playlist,Mediastore,如果可能,如何以编程方式从MediaStore.Audio.Playlists.EXTERNAL\u CONTENT\u URI中删除播放列表 我使用以下代码删除特定的播放列表。当然,它只需要播放列表id private void deletePlaylist(String selectedplaylist) { // // Log.i(TAG, "deletePlaylist"); String playlistid = getPlayListId(selectedplaylist); Co
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 ;
}
我已经创建了一个小应用程序,你可以在其中看到这一点。
如您所见,它首先获取playlid。现在我只有播放列表名。
下面是我的代码以获取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;
}
我使用以下代码删除特定的播放列表。当然,它只需要播放列表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 ;
}
我已经创建了一个小应用程序,你可以在其中看到这一点。
如您所见,它首先获取playlid。现在我只有播放列表名。
下面是我的代码以获取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;
}
要重命名,请执行以下操作:
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);
}
要重命名,请执行以下操作:
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);
}
非常感谢。这正是我所需要的。:)嗨,提奥,我如何修改上面的代码来重命名我的播放列表?提前感谢我现在正在度假,但下周将发布代码9.3.15谢谢。这正是我所需要的。:)嗨,提奥,我如何修改上面的代码来重命名我的播放列表?提前谢谢,我现在正在holidsy上,但下周9.3.15将发布代码