Skip to content

Instantly share code, notes, and snippets.

@geecko86
Created March 12, 2015 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geecko86/c2580bec0a3030137447 to your computer and use it in GitHub Desktop.
Save geecko86/c2580bec0a3030137447 to your computer and use it in GitHub Desktop.
Get filepath from artist and title
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