fixed frame capture for transient videos

This commit is contained in:
Thibault Deckers 2021-09-26 18:07:21 +09:00
parent 214650ebe4
commit 0848881738
3 changed files with 5 additions and 9 deletions

View file

@ -158,7 +158,7 @@ class MediaFileHandler(private val activity: Activity) : MethodCallHandler {
destinationDir = ensureTrailingSeparator(destinationDir) destinationDir = ensureTrailingSeparator(destinationDir)
provider.captureFrame(activity, desiredName, exifFields, bytes, destinationDir, object : ImageOpCallback { provider.captureFrame(activity, desiredName, exifFields, bytes, destinationDir, object : ImageOpCallback {
override fun onSuccess(fields: FieldMap) = result.success(fields) 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)
}) })
} }

View file

@ -56,10 +56,6 @@ abstract class ImageProvider {
throw UnsupportedOperationException() throw UnsupportedOperationException()
} }
open suspend fun scanNewPath(context: Context, path: String, mimeType: String): FieldMap {
throw UnsupportedOperationException()
}
suspend fun exportMultiple( suspend fun exportMultiple(
context: Context, context: Context,
imageExportMimeType: String, imageExportMimeType: String,
@ -203,7 +199,7 @@ abstract class ImageProvider {
val fileName = destinationDocFile.name val fileName = destinationDocFile.name
val destinationFullPath = destinationDir + fileName val destinationFullPath = destinationDir + fileName
return scanNewPath(context, destinationFullPath, exportMimeType) return MediaStoreImageProvider().scanNewPath(context, destinationFullPath, exportMimeType)
} }
@Suppress("BlockingMethodInNonBlockingContext") @Suppress("BlockingMethodInNonBlockingContext")
@ -301,7 +297,7 @@ abstract class ImageProvider {
val fileName = destinationDocFile.name val fileName = destinationDocFile.name
val destinationFullPath = destinationDir + fileName val destinationFullPath = destinationDir + fileName
val newFields = scanNewPath(context, destinationFullPath, captureMimeType) val newFields = MediaStoreImageProvider().scanNewPath(context, destinationFullPath, captureMimeType)
callback.onSuccess(newFields) callback.onSuccess(newFields)
} catch (e: Exception) { } catch (e: Exception) {
callback.onFailure(e) callback.onFailure(e)
@ -332,7 +328,7 @@ abstract class ImageProvider {
scanObsoletePath(context, oldPath, mimeType) scanObsoletePath(context, oldPath, mimeType)
try { try {
callback.onSuccess(scanNewPath(context, newFile.path, mimeType)) callback.onSuccess(MediaStoreImageProvider().scanNewPath(context, newFile.path, mimeType))
} catch (e: Exception) { } catch (e: Exception) {
callback.onFailure(e) callback.onFailure(e)
} }

View file

@ -403,7 +403,7 @@ class MediaStoreImageProvider : ImageProvider() {
MediaScannerConnection.scanFile(context, arrayOf(path), arrayOf(mimeType), null) 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 -> suspendCoroutine { cont ->
MediaScannerConnection.scanFile(context, arrayOf(path), arrayOf(mimeType)) { _, newUri: Uri? -> MediaScannerConnection.scanFile(context, arrayOf(path), arrayOf(mimeType)) { _, newUri: Uri? ->
fun scanUri(uri: Uri?): FieldMap? { fun scanUri(uri: Uri?): FieldMap? {