Why video URI is giving Invalid column?

from the CommonsWare Community archives

At July 1, 2020, 4:04am, brainy15mca asked:

Hi,
I am trying to read video file detail using below code

val resolver = context.contentResolver
val cursor = resolver.query(uri, PROJECTION, null, null, SORT_ORDER);

This is working fine fro android emulator but, I tried to same code on Ssamsung Galaxy M40, with URI

content://media/external/video/media/22

Its throwing below exception:

java.lang.IllegalArgumentException: Invalid column vnd.android.cursor.dir/video


At July 1, 2020, 10:38am, mmurphy replied:

How are you declaring PROJECTION and SORT_ORDER?


At July 1, 2020, 4:25pm, brainy15mca replied:

Here is the way, Its working in android emulator:

private val PROJECTION =
        arrayOf(
                MediaStore.Video.Media.CONTENT_TYPE,
                MediaStore.Video.Media.TITLE,
                MediaStore.Video.Media.DISPLAY_NAME,
                MediaStore.Video.Media.DURATION,
                MediaStore.Video.Media.SIZE,
                MediaStore.Video.Media.DESCRIPTION
        )
private const val SORT_ORDER = MediaStore.Video.Media.DATE_ADDED

At July 1, 2020, 5:00pm, mmurphy replied:

OK. I cannot explain that error. The error suggests that Samsung is trying to treat a MIME type (vnd.android.cursor.dir/video) as the name of a column. You might try removing CONTENT_TYPE from PROJECTION and see if the query runs. If it does, you can use getType() on ContentResolver to get the MIME type.