首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在安卓系统中从MediaStore.Audio.Playlists删除播放列表

如何在安卓系统中从MediaStore.Audio.Playlists删除播放列表
EN

Stack Overflow用户
提问于 2012-10-31 17:20:28
回答 3查看 3K关注 0票数 1

如果可能,如何以编程方式从MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI中删除播放列表?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-11-02 18:18:32

我使用以下代码来删除特定的播放列表。当然,它所需要的是播放列表id。

代码语言:javascript
复制
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。

代码语言:javascript
复制
    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;
    }
票数 7
EN

Stack Overflow用户

发布于 2015-03-09 19:25:32

要重命名,我有以下内容:

代码语言:javascript
复制
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);
}
票数 0
EN

Stack Overflow用户

发布于 2018-07-12 17:09:09

代码语言:javascript
复制
/**
 * 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);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13154662

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档