public static String getFileFromContentUri(Context context, Uri contentUri) {
        if (contentUri == null) {
            return null;
        }
        if (ContentResolver.SCHEME_FILE.equals(contentUri.getScheme())) {
            return contentUri.toString();
        }
        String filePath = null;
        String[] filePathColumn = {MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.DISPLAY_NAME};
        ContentResolver contentResolver = context.getContentResolver();
        Cursor cursor = contentResolver.query(contentUri, filePathColumn, null,
                null, null);
        if (cursor != null) {
            cursor.moveToFirst();
            filePath = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA));
            cursor.close();
        }
        return filePath;
    }
Gets the corresponding path to a file from the given content:// URI

@param context    Context
@param contentUri The content:// URI to find the file path from
@return the file path as a string
dkplayer-sample/src/main/java/xyz/doikki/dkplayer/util/Utils.java