LightCompressor icon indicating copy to clipboard operation
LightCompressor copied to clipboard

Cannot compress to data directory

Open Andoctorey opened this issue 2 years ago • 4 comments

Cannot compress to ContextCompat.getDataDir(context) to not ask storage permission. In version 1.0.1 it worked without problems. Now it crashes:

 java.lang.IllegalArgumentException: Primary directory (invalid) not allowed for content://media/external_primary/video/media; allowed directories are [DCIM, Movies, Pictures]
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:172)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
        at android.content.ContentProviderProxy.insert(ContentProviderNative.java:557)
        at android.content.ContentResolver.insert(ContentResolver.java:2218)
        at android.content.ContentResolver.insert(ContentResolver.java:2173)
        at com.abedelazizshe.lightcompressorlibrary.VideoCompressor.saveVideoFile(VideoCompressor.kt:179)
        at com.abedelazizshe.lightcompressorlibrary.VideoCompressor.access$saveVideoFile(VideoCompressor.kt:24)
        at com.abedelazizshe.lightcompressorlibrary.VideoCompressor$doVideoCompression$1.invokeSuspend(VideoCompressor.kt:99)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:233)
        at android.os.Looper.loop(Looper.java:344)
        at android.app.ActivityThread.main(ActivityThread.java:8191)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)

Andoctorey avatar Apr 20 '22 14:04 Andoctorey

@Andoctorey Thank you for opening this issue.

I have added a fix to allow you to pass a isExternal (true/false) flag which will save to files dir if it is false.

I will release version 1.2.0 shortly.

Thank you.

AbedElazizShe avatar Jun 06 '22 05:06 AbedElazizShe

Device Name ; Poco F1 Android 10 It only compress below 1min video & video also not get played What is the max size of the video that can be compressed? & for 1Gb Video how can we decrease the compression time?

Afaquejaya avatar Jun 09 '22 13:06 Afaquejaya

  1. Updated from 1.0.1 to 1.2.0.
  2. Made following config:
val convertingFile = File(ContextCompat.getExternalFilesDirs(context, null), video.mp4)
convertingFile.createNewFile()
storageConfiguration = StorageConfiguration(
                        saveAt =convertingFile.path,
                        isExternal = false,
                    ),
  1. Removed storage permission
  2. Got following error:

compress /storage/emulated/0/Android/data/app.package/files/media/FSa5CPc9UQSrQLi1jYA8bZsdVNI3/-N8JkLYRwKD02H1FUxTr/1659279748873.mp0.tmp

2022-07-31 22:02:45.552 9628-9628/app.ploshcha E/AndroidRuntime: FATAL EXCEPTION: main Process: app.package, PID: 9628 java.io.FileNotFoundException: : open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:575) at java.io.FileInputStream.(FileInputStream.java:160) at com.abedelazizshe.lightcompressorlibrary.VideoCompressor.saveVideoInInternal(VideoCompressor.kt:214) at com.abedelazizshe.lightcompressorlibrary.VideoCompressor.saveVideoFile(VideoCompressor.kt:180) at com.abedelazizshe.lightcompressorlibrary.VideoCompressor.access$saveVideoFile(VideoCompressor.kt:26) at com.abedelazizshe.lightcompressorlibrary.VideoCompressor$doVideoCompression$1.invokeSuspend(VideoCompressor.kt:104) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:233) at android.os.Looper.loop(Looper.java:344) at android.app.ActivityThread.main(ActivityThread.java:8210) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034) Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@4a2695f, Dispatchers.Main] Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) at libcore.io.Linux.open(Native Method) at libcore.io.ForwardingOs.open(ForwardingOs.java:567) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:273) at libcore.io.ForwardingOs.open(ForwardingOs.java:567) at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8092) at libcore.io.IoBridge.open(IoBridge.java:561) ... 15 more

Andoctorey avatar Jul 31 '22 15:07 Andoctorey

anyone here have solution for this case? @Andoctorey @AbedElazizShe

  1. Updated from 1.0.1 to 1.2.0.
  2. Made following config:
val convertingFile = File(ContextCompat.getExternalFilesDirs(context, null), video.mp4)
convertingFile.createNewFile()
storageConfiguration = StorageConfiguration(
                        saveAt =convertingFile.path,
                        isExternal = false,
                    ),
  1. Removed storage permission
  2. Got following error:

compress /storage/emulated/0/Android/data/app.package/files/media/FSa5CPc9UQSrQLi1jYA8bZsdVNI3/-N8JkLYRwKD02H1FUxTr/1659279748873.mp0.tmp 2022-07-31 22:02:45.552 9628-9628/app.ploshcha E/AndroidRuntime: FATAL EXCEPTION: main Process: app.package, PID: 9628 java.io.FileNotFoundException: : open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:575) at java.io.FileInputStream.(FileInputStream.java:160) at com.abedelazizshe.lightcompressorlibrary.VideoCompressor.saveVideoInInternal(VideoCompressor.kt:214) at com.abedelazizshe.lightcompressorlibrary.VideoCompressor.saveVideoFile(VideoCompressor.kt:180) at com.abedelazizshe.lightcompressorlibrary.VideoCompressor.access$saveVideoFile(VideoCompressor.kt:26) at com.abedelazizshe.lightcompressorlibrary.VideoCompressor$doVideoCompression$1.invokeSuspend(VideoCompressor.kt:104) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:233) at android.os.Looper.loop(Looper.java:344) at android.app.ActivityThread.main(ActivityThread.java:8210) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034) Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@4a2695f, Dispatchers.Main] Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) at libcore.io.Linux.open(Native Method) at libcore.io.ForwardingOs.open(ForwardingOs.java:567) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:273) at libcore.io.ForwardingOs.open(ForwardingOs.java:567) at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8092) at libcore.io.IoBridge.open(IoBridge.java:561) ... 15 more

anggit97 avatar Aug 18 '22 09:08 anggit97

Could you please try version 1.2.2 and let me know if the issue is fixed?

AbedElazizShe avatar Dec 13 '22 13:12 AbedElazizShe

Thanks a lot for fixing this. Just tested few times and got empty file in onSuccess.

Andoctorey avatar Dec 13 '22 16:12 Andoctorey

@Andoctorey, thank you for confirming this. Could you please let me know what is the configurations you use that result in an empty file in onSuccess. I am trying to reproduce it so I can fix the issue ASAP.

Thanks a lot

AbedElazizShe avatar Dec 17 '22 08:12 AbedElazizShe

@AbedElazizShe

Configuration:

                    uris = listOf(Uri.fromFile(tmpFile)),
                    configureWith = Configuration(
                        quality = VideoQuality.HIGH,
                        isMinBitrateCheckEnabled = true,
                    ),
                    appSpecificStorageConfiguration = AppSpecificStorageConfiguration(
                        videoName = convertingFile.name,
                        subFolderName = convertingFile.parent
                    ),

Logs:

18:19:33.065 VideoCompressor       I  compress /storage/emulated/0/Android/data/app.package/files/media/FSa5CPc9UQSrQLi1jYA8bZsdVNI3/-NJUnpJx8qRVhjbCqV1C/1671275962698.mp0.tmp
18:19:33.065                       I  tmpFile.path = /storage/emulated/0/Android/data/app.package/files/media/FSa5CPc9UQSrQLi1jYA8bZsdVNI3/-NJUnpJx8qRVhjbCqV1C/1671275962698.mp0.tmp
18:19:33.065                       I  convertingFile.name = 1671275962698.mp4.tmp
18:19:33.065                       I  convertingFile.parent = /storage/emulated/0/Android/data/app.package/files/media/FSa5CPc9UQSrQLi1jYA8bZsdVNI3/-NJUnpJx8qRVhjbCqV1C, exists = true
18:19:33.270 VideoComp...compress  I  compressing video 0: onStart, file.size: 26.11 MB
18:19:33.370                       I  compressing video 0: onSuccess, result file.size: 0 MB

OS: Android 13.

Andoctorey avatar Dec 17 '22 11:12 Andoctorey