From 7d903348670d1b7461b7f1427927336a6171ab23 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Thu, 26 Jan 2017 20:18:07 +0100 Subject: [PATCH] fix scrobbler --- .../android/vanilla/MediaUtils.java | 19 +++++++ .../android/vanilla/PlaybackService.java | 56 ++++++++++--------- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/src/ch/blinkenlights/android/vanilla/MediaUtils.java b/src/ch/blinkenlights/android/vanilla/MediaUtils.java index 645859fa..599b7d7a 100644 --- a/src/ch/blinkenlights/android/vanilla/MediaUtils.java +++ b/src/ch/blinkenlights/android/vanilla/MediaUtils.java @@ -562,6 +562,25 @@ public class MediaUtils { return matrixCursor; } + /** + * Returns the id's used by Androids native media database for given song + * + * @param context the context to use + * @param song the song to query + * @return long { song_id, album_id, artist_id } - all set to -1 on error + */ + public static long[] getAndroidMediaIds(Context context, Song song) { + long[] result = { -1, -1, -1 }; + String[] projection = new String[]{ MediaStore.Audio.Media._ID, MediaStore.Audio.Media.ALBUM_ID, MediaStore.Audio.Media.ARTIST_ID }; + Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, MediaStore.Audio.Media.DATA+"=?", new String[] { song.path }, null); + if (cursor.moveToFirst()) { + for (int i=0; i