Search code examples
androidkotlinandroid-6.0-marshmallowandroid-6.0.1-marshmallow

ClassCastException: MediaMetadataRetriever cannot be cast to AutoCloseable


I tried to use MediaMetadataRetriever with Kotlin use:

MediaMetadataRetriever().apply {
    setDataSource(context, uri)
}.use {
    ...
}

But it gives me an error on Android 6 Marshmallow (23 API):

java.lang.ClassCastException: android.media.MediaMetadataRetriever cannot be cast to java.lang.AutoCloseable

Why so?


Solution

  • MediaMetadataRetriever implements AutoCloseable since API level 29.