From: Jorge Ruesga Date: Fri, 27 Jun 2014 23:04:03 +0000 (+0200) Subject: apollo: update media cursor according to passed uri X-Git-Tag: android-x86-6.0-r1~251 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=522afddb9445d5388491362077d17f262b1ff9a9;p=android-x86%2Fpackages-apps-Eleven.git apollo: update media cursor according to passed uri Check whether an external app is passing a MediaStore.File or MediaStore.Audio.Media uri and update the cursor according to that uri. JIRA: CYAN-4437 Issue: https://jira.cyanogenmod.org/browse/CYAN-4437 Change-Id: Ib378be6c2906bf35a69a34a95a81d1f3f77f9cce Signed-off-by: Jorge Ruesga --- diff --git a/src/com/andrew/apollo/MusicPlaybackService.java b/src/com/andrew/apollo/MusicPlaybackService.java index 6275708..d7b3f9c 100644 --- a/src/com/andrew/apollo/MusicPlaybackService.java +++ b/src/com/andrew/apollo/MusicPlaybackService.java @@ -1000,11 +1000,21 @@ public class MusicPlaybackService extends Service { private void updateCursor(final String selection, final String[] selectionArgs) { synchronized (this) { closeCursor(); - mCursor = openCursorAndGoToFirst(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, PROJECTION, selection, selectionArgs); } + updateAlbumCursor(); + } + + private void updateCursor(final Uri uri) { + synchronized (this) { + closeCursor(); + mCursor = openCursorAndGoToFirst(uri, PROJECTION, null, null); + } + updateAlbumCursor(); + } + private void updateAlbumCursor() { long albumId = getAlbumId(); if (albumId >= 0) { mAlbumCursor = openCursorAndGoToFirst(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, @@ -1590,23 +1600,28 @@ public class MusicPlaybackService extends Service { // If mCursor is null, try to associate path with a database cursor if (mCursor == null) { - final ContentResolver resolver = getContentResolver(); - Uri uri; - String where; - String selectionArgs[]; - if (path.startsWith("content://media/")) { - uri = Uri.parse(path); - where = null; - selectionArgs = null; + Uri uri = Uri.parse(path); + long id = -1; + try { + id = Long.valueOf(uri.getLastPathSegment()); + } catch (NumberFormatException ex) { + // Ignore + } + + if (id != -1 && path.startsWith(MediaStore.Audio.Media. + EXTERNAL_CONTENT_URI.toString())) { + updateCursor(uri); + + } else if (id != -1 && path.startsWith(MediaStore.Files.getContentUri( + "external").toString())) { + updateCursor(id); + } else { - uri = MediaStore.Audio.Media.getContentUriForPath(path); - where = MediaStore.Audio.Media.DATA + "=?"; - selectionArgs = new String[] { - path - }; + String where = MediaStore.Audio.Media.DATA + "=?"; + String[] selectionArgs = new String[] {path}; + updateCursor(where, selectionArgs); } try { - updateCursor(where, selectionArgs); if (mCursor != null) { ensurePlayListCapacity(1); mPlayListLen = 1;