Skip to content

Commit eec03a7

Browse files
author
xufuji456
committed
update: release in finally
1 parent f501b12 commit eec03a7

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ class VideoHandleActivity : BaseActivity() {
286286
}
287287
11 -> { //convert video to picture
288288
outputPath = PATH + File.separator + "Video2Image/"
289-
val imageFile = File(outputPath)
290-
if (!imageFile.exists()) {
289+
val imageFile = outputPath?.let { File(it) }
290+
if (imageFile != null && !imageFile.exists()) {
291291
if (!imageFile.mkdir()) {
292292
return
293293
}
@@ -400,7 +400,7 @@ class VideoHandleActivity : BaseActivity() {
400400
val cmdList = ArrayList<Array<String>>()
401401
//the resolution of photo which you want to convert
402402
val resolution = "640x480"
403-
for (file in files) {
403+
for (file in files!!) {
404404
val inputPath = file.absolutePath
405405
val outputPath = tempPath + file.name
406406
val convertCmd = FFmpegUtil.convertResolution(inputPath, resolution, outputPath)
@@ -421,19 +421,23 @@ class VideoHandleActivity : BaseActivity() {
421421
var width = 0
422422
var height = 0
423423
var rotateDegree = 0
424+
var retriever: MediaMetadataRetriever ?= null
424425
try {
425-
val retriever = MediaMetadataRetriever()
426+
retriever = MediaMetadataRetriever()
426427
retriever.setDataSource(videoPath)
427428
val mWidth = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)
428429
val mHeight = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)
429-
width = Integer.valueOf(mWidth)
430-
height = Integer.valueOf(mHeight)
430+
width = mWidth?.let { Integer.valueOf(it) }!!
431+
height = mHeight?.let { Integer.valueOf(it) }!!
431432
val rotate = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION)
432-
rotateDegree = Integer.valueOf(rotate)
433-
retriever.release()
433+
if (!rotate.isNullOrEmpty()) {
434+
rotateDegree = Integer.valueOf(rotate)
435+
}
434436
Log.e(TAG, "retrieve width=$width--height=$height--rotate=$rotate")
435437
} catch (e: Exception) {
436438
Log.e(TAG, "retrieve error=$e")
439+
} finally {
440+
retriever?.release()
437441
}
438442

439443
val start = System.currentTimeMillis()

0 commit comments

Comments
 (0)