2011-11-24 23 views
5

MediaStore.Playlists.Members.moveItem अपने Android एप्लिकेशन में एक प्लेलिस्ट से किसी आइटम को निकालने के लिए निम्न कोड का उपयोग कर रहे हैं:वैकल्पिक

private void removeFromPlaylist(long playlistId, int loc) 
{ 
    ContentResolver resolver = getApplicationContext().getContentResolver(); 
    Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId); 
    resolver.delete(uri, MediaStore.Audio.Playlists.Members.PLAY_ORDER+" = "+loc, null); 
    for(int i=loc+1;i<playSongIDs.length;i++) { 
     MediaStore.Audio.Playlists.Members.moveItem(resolver,playlistId,i, i-1); 
    } 
} 

मैं वर्तमान में Android 2.2 पुस्तकालय का उपयोग कर रहा है और इस एकमात्र चीज है जिसे मुझे एंड्रॉइड 2.1 का उपयोग करने के लिए बदलने की जरूरत है। क्या किसी प्लेलिस्ट से किसी आइटम को निकालने और हटाए गए आइटम के बाद आइटम का ऑर्डर समायोजित करने के लिए कोई वैकल्पिक तरीका है?

उत्तर

1

Mediastore के कोड को देखकर हम इस समाधान ठीक काम करने के लिए लगता है कि के साथ बाहर आया:

/** 
* Convenience method to move a playlist item to a new location 
* @param res The content resolver to use 
* @param playlistId The numeric id of the playlist 
* @param from The position of the item to move 
* @param to The position to move the item to 
* @return true on success 
*/ 
private boolean moveItem(ContentResolver res, long playlistId, int from, int to) { 
    Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", 
      playlistId) 
      .buildUpon() 
      .appendEncodedPath(String.valueOf(from)) 
      .appendQueryParameter("move", "true") 
      .build(); 
    ContentValues values = new ContentValues(); 
    values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, to); 
    return res.update(uri, values, null, null) != 0; 
} 
संबंधित मुद्दे