AbedElazizShe / LightCompressor

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

RuntimeException: setDataSource failed #68

Closed ShaQib07 closed 3 years ago

ShaQib07 commented 3 years ago

Fatal Exception: java.lang.RuntimeException: setDataSource failed: status = 0x80000000 at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java) at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:81) at com.abedelazizshe.lightcompressorlibrary.Compressor.compressVideo(Compressor.kt:45) at com.abedelazizshe.lightcompressorlibrary.VideoCompressor$startCompression$2.invokeSuspend(VideoCompressor.kt:97) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

AbedElazizShe commented 3 years ago

@ShaQib07 Thank you for opening this issue, please provide more details to undertsand how this is happening:

Thank you.

ShaQib07 commented 3 years ago

@AbedElazizShe Thanks for your reply. Here's the information you've asked for Android OS : 9 | Device : Galaxy S9 Library Version = 0.7.7

`fun downloadVideo() {
    val fileExists = findVideoFile(context, getPublicVideoFileName())
    Timber.d("GSK | $fileExists")
    if (fileExists) {
        videoDownloadLiveData.postValue(Resource.Success(context.getString(R.string.file_already_exists)))
    } else {
        val mediaData = messageData?.message?.media
        mediaData?.getContentTemporaryUrl(object : CallbackListener<String>() {
            override fun onSuccess(url: String?) {
                url?.let {
                    val outputFile = File(getOutputDirectory(), getLocalVideoFileName())
                    viewModelScope.launch(Dispatchers.IO) {
                        try {
                            Timber.d("GSK | Started")
                            videoDownloadLiveData.postValue(Resource.Loading())
                            val downloadingUrl = URL(it)
                            val urlConnection: URLConnection = URL(it).openConnection()
                            val contentLength: Int = urlConnection.contentLength
                            val stream = DataInputStream(downloadingUrl.openStream())
                            val buffer = ByteArray(contentLength)
                            stream.readFully(buffer)
                            stream.close()
                            val fos = DataOutputStream(FileOutputStream(outputFile))
                            fos.apply {
                                write(buffer)
                                flush()
                                close()
                            }
                            val div = outputFile.length().div(1024 * 1024)
                            Timber.d("GSK | Closed - Compressing | $div")
                            compress(outputFile)
                        } catch (e: Exception) {
                            Timber.d("Downloading failed $e")
                            videoDownloadLiveData.postValue(Resource.Error(e))
                        }
                    }
                }
            }
        })
    }
}`

`private fun compress(sourceFile: File) {
    viewModelScope.launch {
        val compressedFile = File(getOutputDirectory(), getPublicVideoFileName())
        VideoCompressor.start(
            sourceFile.absolutePath,
            compressedFile.absolutePath,
            object : CompressionListener {
                override fun onProgress(percent: Float) {}

                override fun onStart() {}

                override fun onSuccess() {
                    writeVideoFileIntoPublicDirectory(compressedFile, sourceFile)
                }

                override fun onFailure(failureMessage: String) {
                    videoDownloadLiveData.postValue(Resource.Error(Throwable(failureMessage)))
                }

                override fun onCancelled() {
                    videoDownloadLiveData.postValue(Resource.Error(Throwable("Cancelled")))
                }

            },
            VideoQuality.VERY_HIGH,
            isMinBitRateEnabled = false,
            keepOriginalResolution = false
        )
    }
}`
AbedElazizShe commented 3 years ago

@ShaQib07 thank you for the details and sorry for the late reply. Could you please try to use the latest version of the library ?

soelling commented 3 years ago

@AbedElazizShe I have reproduced the same issue on following device: Android OS: 7.0 Device: Samsung Galaxy XCover Library Version: 0.9

ShaQib07 commented 3 years ago

@AbedElazizShe sorry, currently working on something else, but I'll surely get back to it later and let you know.

AbedElazizShe commented 3 years ago

@soelling @ShaQib07 thank you for yor replies. I tested version 0.9.2 on the mentioned devices and i didn't have any issues. Could you please try the sample app and let me know if you're having the same issue?

deepakjain1989 commented 7 months ago

@AbedElazizShe I have reproduced the same issue on following device: Android OS: android11 Device: Mi A3 Library Version:1.2.2