Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getVideoMetaData and getImageMetaData size is wrone on android platform, is ok on ios platform #279

Open
krmao opened this issue Mar 26, 2024 · 4 comments

Comments

@krmao
Copy link

krmao commented Mar 26, 2024

Current behavior

ios size is ok, but android is wrong, should 'x 1024'

Expected behavior

android size x 1024

Platform

  • Android

React Native Version

0.72.4

React Native Compressor Version

1.8.24

Reproducible Steps And Demo

log getImageMetaData.size / 1024 / 1024 to XXX mb
log getVideoMetaData.size / 1024 / 1024 to XXX mb

quick fix

const getImageInfo = (filePath: string) => {
  return getImageMetaData(filePath).then(result => ({
    ...result,
    size: displayUtil.IS_IOS ? result.size : result.size * 1024, // android 下 size 发现少了 1024倍
  }));
};

const getVideoInfo = (filePath: string) => {
  return getVideoMetaData(filePath).then(result => ({
    ...result,
    size: displayUtil.IS_IOS ? result.size : result.size * 1024, // android 下 size 发现少了 1024倍
  }));
};
@krmao
Copy link
Author

krmao commented Mar 26, 2024

and also clearCache will got crash

image

@krmao
Copy link
Author

krmao commented Mar 28, 2024

new patch for a test

diff --git a/node_modules/react-native-compressor/ios/Utils/CreateVideoThumbnail.swift b/node_modules/react-native-compressor/ios/Utils/CreateVideoThumbnail.swift
index 1a77b2b..0ed81ad 100644
--- a/node_modules/react-native-compressor/ios/Utils/CreateVideoThumbnail.swift
+++ b/node_modules/react-native-compressor/ios/Utils/CreateVideoThumbnail.swift
@@ -79,6 +79,12 @@ class CreateVideoThumbnail: NSObject {
         cacheDirectoryPath = (cacheDirectoryPath as NSString).appendingPathComponent(cachePathDir)
 
         let fm = FileManager.default
+
+        if !fm.fileExists(atPath: cacheDirectoryPath) {
+            reject("Error", "Directory does not exist", nil)
+            return
+        }
+
         do {
             let files = try fm.contentsOfDirectory(atPath: cacheDirectoryPath)
             for file in files {
diff --git a/node_modules/react-native-compressor/ios/Video/VideoMain.swift b/node_modules/react-native-compressor/ios/Video/VideoMain.swift
index bc8205c..08c1393 100644
--- a/node_modules/react-native-compressor/ios/Video/VideoMain.swift
+++ b/node_modules/react-native-compressor/ios/Video/VideoMain.swift
@@ -206,7 +206,7 @@ class VideoCompressor {
 
     func manualCompressionHelper(url: URL, options: [String: Any], onProgress: @escaping (Float) -> Void,  onCompletion: @escaping (URL) -> Void, onFailure: @escaping (Error) -> Void){
         let uuid:String = options["uuid"] as! String
-        var bitRate=options["bitrate"] as! Float?;
+        var bitRate = (options["bitrate"] as? NSNumber)?.floatValue;
         let progressDivider=options["progressDivider"] as? Int ?? 0
         let asset = AVAsset(url: url)
         guard asset.tracks.count >= 1 else {

@numandev1
Copy link
Owner

@krmao can you make PR so i can merge?

@krmao
Copy link
Author

krmao commented Mar 30, 2024

@numandev1 I did it now, you can check and merge. #281
Please remind me when there's a new version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants