kdr*_*der 1 android mediastore playlist
如果可能,我如何以MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI编程方式删除播放列表?
我使用以下代码删除特定的播放列表.它所需要的只是播放列表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 ;
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个小应用程序,您可以在其中看到这一点. 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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2688 次 |
| 最近记录: |