I have resource (music file) pointed by Uri. How can I check if it is available before I try to play it with MediaPlayer?
Its Uri is stored in database, so when the file
Try a function like:
public static boolean checkURIResource(Context context, Uri uri) { Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); boolean doesExist= (cursor != null && cursor.moveToFirst()); if (cursor != null) { cursor.close(); } return doesExist; }