numandev1 / react-native-compressor

🗜️Compress Image, Video, and Audio same like Whatsapp 🚀✨
MIT License
883 stars 85 forks source link

Getting crash when compressing video in iOS #69

Closed hongkheng closed 2 years ago

hongkheng commented 2 years ago

I'm facing a crash in iOS after selecting a video in the camera roll. It's happening for all videos.

The library i'm using for Cameraroll is @react-native-community/cameraroll.

The uri path that I'm passing to the compressVideo method is of the form ph://1ABDEA26-31B1-4EB0-B579-A7B8D8B49EED/L0/001. I even tried to use react-native-fs to use the path /var/mobile/Containers/Data/Application/4AF55096-E2CA-4BE1-93D5-2D252D226886/Library/Caches/IMG_1294.mp4 and the same crash still happens.

It's crashing at getFileSize method in VideoCompressor.swift file.

// crash happened here due to nil value for fileSizeValue
try? fileSizeValue = (fileURL?.resourceValues(forKeys: [URLResourceKey.fileSizeKey]).allValues.first?.value as! Double?)!  
   func getfileSize(forURL url: Any) -> Double {
        var fileURL: URL?
        var fileSize: Double = 0.0
        if (url is URL) || (url is String)
        {
            if (url is URL) {
                fileURL = url as? URL
            }
            else {
                fileURL = URL(fileURLWithPath: url as! String)
            }
            var fileSizeValue = 0.0
            try? fileSizeValue = (fileURL?.resourceValues(forKeys: [URLResourceKey.fileSizeKey]).allValues.first?.value as! Double?)!  // <-- crash happened here due to nil value for fileSizeValue

            if fileSizeValue > 0.0 {
                fileSize = (Double(fileSizeValue) / (1024 * 1024))
            }
        }
        return fileSize
    }

What's the expected path we should be passing to compressVideo assuming we are not using react-native-image-picker like in your example?

my react-native is v0.63, I'm using 0.5.9 version of the library.

numandev1 commented 2 years ago

@hongkheng we are expecting paths like file:///path_of_file.extension.

can you add reproducible example so I can add support for ph:// files?

hongkheng commented 2 years ago

@nomi9995 I will need some time to reproduce that, will be nice to have support for ph:// path.

dhayaljaswantgit commented 2 years ago

Hello Guys,

Anybody able to fix this issue, I'm facing the same on iOS.

Thanks

numandev1 commented 2 years ago

@hongkheng @dhayaljaswantgit if you add minimal repro issue through the new GitHub repo then I can fix it quickly. thanks

numandev1 commented 2 years ago

@hongkheng @dhayaljaswantgit fixed by 1.4.0 version