Skip to content

Commit cb05592

Browse files
Fix lint: replace MediaMetadataRetriever.use{} with try/finally
AutoCloseable is only implemented by MediaMetadataRetriever from API 29; minSdk is 24. Use release() in a try/finally block instead, which is available from API 14. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ba564ce commit cb05592

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

videocompressor/src/main/java/com/akshayashokcode/videocompressor/util/VideoTranscoder.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,18 @@ internal object VideoTranscoder {
6262
srcFmt.getInteger(MediaFormat.KEY_ROTATION) else 0
6363

6464
// Duration for progress reporting
65+
// MediaMetadataRetriever only implements AutoCloseable on API 29+; use release() instead.
6566
val totalUs = if (srcFmt.containsKey(MediaFormat.KEY_DURATION))
6667
srcFmt.getLong(MediaFormat.KEY_DURATION)
67-
else MediaMetadataRetriever().use { r ->
68-
r.setDataSource(context, sourceUri)
69-
r.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
70-
?.toLong()?.times(1000L) ?: 0L
68+
else {
69+
val r = MediaMetadataRetriever()
70+
try {
71+
r.setDataSource(context, sourceUri)
72+
r.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
73+
?.toLong()?.times(1000L) ?: 0L
74+
} finally {
75+
r.release()
76+
}
7177
}
7278

7379
// Compute coded output dimensions (must be even; respect rotation swap)

0 commit comments

Comments
 (0)