AbedElazizShe / LightCompressor

A powerful and easy-to-use video compression library for android uses MediaCodec API.
Apache License 2.0
533 stars 116 forks source link

Url returned for Android 9 and lower is wrong #183

Open akrulec opened 11 months ago

akrulec commented 11 months ago

This is how I use the video compressor:

VideoCompressor.start(
                context = CoPilotApplication.application.applicationContext,
                uris = listOf(uri),
                isStreamable = true,
                sharedStorageConfiguration =
                    SharedStorageConfiguration(
                        saveAt = SaveLocation.movies, // => default is movies
                    ),
                configureWith =
                    Configuration(
                        quality = VideoQuality.LOW,
                        isMinBitrateCheckEnabled = false,
                        // This needs to be different every time.
                        videoNames = listOf(UUID.randomUUID().toString())),
                listener =
                    object : CompressionListener {
                        override fun onProgress(index: Int, percent: Float) {
                            // Nothing
                        }

                        override fun onStart(index: Int) {
                            // Nothing really.
                        }

                        override fun onSuccess(index: Int, size: Long, path: String?) {
                            Timber.d("File compressed successfully: $path, $size")
                            // Upload video.
                            analyticsRepository.logEvent(Event.Chat.VIDEO_SENT, null)
                            path?.let { addMediaViewModel.uploadVideo(File(path)) }
                        }

                        override fun onFailure(index: Int, failureMessage: String) {
                            Timber.e(failureMessage)
                            addMediaViewModel.error()
                        }

                        override fun onCancelled(index: Int) {
                            // Make UI changes, cleanup, etc.
                            Timber.e("compression has been cancelled")
                            addMediaViewModel.error()
                        }
                    },
            )

When I added some print statements, I tell video compressor the video should be called 30758f51-8e0a-449c-a421-2268cd3953c1. It says, I've compressed video, and it's here /storage/emulated/0/Movies/30758f51-8e0a-449c-a421-2268cd3953c1_temp.mp4, but there is no such file there, it's /storage/emulated/0/Movies/30758f51-8e0a-449c-a421-2268cd3953c1.mp4 . I'm using version com.github.AbedElazizShe:LightCompressor:1.3.2 . Is this intended? How do I get around this?

keyur-Dev commented 9 months ago

Hey @akrulec , I met with the same issue while using this library. I investigated some parts and found that if we give isStreamable=true, it adds _temp to the file name we have given. I just changed it to false and it worked perfectly. (I am using android 13 on my device)