From 084888173802bd0dab925c3cbac7800ba2b7accf Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Sun, 26 Sep 2021 18:07:21 +0900 Subject: [PATCH] fixed frame capture for transient videos --- .../thibault/aves/channel/calls/MediaFileHandler.kt | 2 +- .../thibault/aves/model/provider/ImageProvider.kt | 10 +++------- .../aves/model/provider/MediaStoreImageProvider.kt | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/MediaFileHandler.kt b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/MediaFileHandler.kt index 7fe3715fc..908d87450 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/MediaFileHandler.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/MediaFileHandler.kt @@ -158,7 +158,7 @@ class MediaFileHandler(private val activity: Activity) : MethodCallHandler { destinationDir = ensureTrailingSeparator(destinationDir) provider.captureFrame(activity, desiredName, exifFields, bytes, destinationDir, object : ImageOpCallback { override fun onSuccess(fields: FieldMap) = result.success(fields) - override fun onFailure(throwable: Throwable) = result.error("captureFrame-failure", "failed to capture frame", throwable.message) + override fun onFailure(throwable: Throwable) = result.error("captureFrame-failure", "failed to capture frame for uri=$uri", throwable.message) }) } diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/ImageProvider.kt b/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/ImageProvider.kt index a52a733b1..45db9be83 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/ImageProvider.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/ImageProvider.kt @@ -56,10 +56,6 @@ abstract class ImageProvider { throw UnsupportedOperationException() } - open suspend fun scanNewPath(context: Context, path: String, mimeType: String): FieldMap { - throw UnsupportedOperationException() - } - suspend fun exportMultiple( context: Context, imageExportMimeType: String, @@ -203,7 +199,7 @@ abstract class ImageProvider { val fileName = destinationDocFile.name val destinationFullPath = destinationDir + fileName - return scanNewPath(context, destinationFullPath, exportMimeType) + return MediaStoreImageProvider().scanNewPath(context, destinationFullPath, exportMimeType) } @Suppress("BlockingMethodInNonBlockingContext") @@ -301,7 +297,7 @@ abstract class ImageProvider { val fileName = destinationDocFile.name val destinationFullPath = destinationDir + fileName - val newFields = scanNewPath(context, destinationFullPath, captureMimeType) + val newFields = MediaStoreImageProvider().scanNewPath(context, destinationFullPath, captureMimeType) callback.onSuccess(newFields) } catch (e: Exception) { callback.onFailure(e) @@ -332,7 +328,7 @@ abstract class ImageProvider { scanObsoletePath(context, oldPath, mimeType) try { - callback.onSuccess(scanNewPath(context, newFile.path, mimeType)) + callback.onSuccess(MediaStoreImageProvider().scanNewPath(context, newFile.path, mimeType)) } catch (e: Exception) { callback.onFailure(e) } diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/MediaStoreImageProvider.kt b/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/MediaStoreImageProvider.kt index 81aad7c89..918a6990b 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/MediaStoreImageProvider.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/model/provider/MediaStoreImageProvider.kt @@ -403,7 +403,7 @@ class MediaStoreImageProvider : ImageProvider() { MediaScannerConnection.scanFile(context, arrayOf(path), arrayOf(mimeType), null) } - override suspend fun scanNewPath(context: Context, path: String, mimeType: String): FieldMap = + suspend fun scanNewPath(context: Context, path: String, mimeType: String): FieldMap = suspendCoroutine { cont -> MediaScannerConnection.scanFile(context, arrayOf(path), arrayOf(mimeType)) { _, newUri: Uri? -> fun scanUri(uri: Uri?): FieldMap? {