fix android ci, replace use with try-finally
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
c2703d215b
commit
dfe96eb30c
1 changed files with 7 additions and 2 deletions
|
|
@ -349,12 +349,17 @@ class MainService : Service() {
|
|||
).apply {
|
||||
setOnImageAvailableListener({ imageReader: ImageReader ->
|
||||
try {
|
||||
imageReader.acquireLatestImage().use { image ->
|
||||
if (image == null) return@setOnImageAvailableListener
|
||||
// https://stackoverflow.com/questions/35136715/try-with-resources-use-extension-function-in-kotlin-does-not-always-work
|
||||
// https://stackoverflow.com/questions/72537045/kotlin-use-with-autocloseable-type-and-a-lambda-returning-boolean
|
||||
val image = imageReader.acquireLatestImage()
|
||||
if (image == null) return@setOnImageAvailableListener
|
||||
try {
|
||||
val planes = image.planes
|
||||
val buffer = planes[0].buffer
|
||||
buffer.rewind()
|
||||
onVideoFrameUpdate(buffer)
|
||||
} finally {
|
||||
image.close()
|
||||
}
|
||||
} catch (ignored: java.lang.Exception) {
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue