Created
March 12, 2015 23:31
-
-
Save geecko86/c2580bec0a3030137447 to your computer and use it in GitHub Desktop.
Get filepath from artist and title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getPath(Context context, String artist, String track) { | |
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); | |
Uri MediaUri = Media.EXTERNAL_CONTENT_URI; | |
String[] columns = {Media.ARTIST, Media.TITLE, | |
Media._ID, Media.DATA}; | |
String selection = Media.ARTIST + "=? AND " + Media.TITLE + "=?"; | |
String[] selectionArgs = new String[]{artist, track}; | |
Cursor mediaCursor = context.getContentResolver() | |
.query(MediaUri, columns, selection, selectionArgs, null); | |
String path = null; | |
if (mediaCursor.moveToFirst()) | |
path = mediaCursor.getString(3); | |
mediaCursor.close(); | |
return path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment