Skip to content

Commit 7765fd9

Browse files
committed
refactor: maxsize and compressionMethod props
1 parent d3a5dd3 commit 7765fd9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

ios/Video/VideoCompressor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func makeValidUri(filePath: String) -> String {
265265
.appendingPathExtension("mp4")
266266
tmpURL = URL(string:makeValidUri(filePath: tmpURL.absoluteString))!
267267

268-
let maxSize = 640.0;
268+
let maxSize:Float = options["maxSize"] as! Float;
269269
var _bitRate=bitRate;
270270
let asset = AVAsset(url: url)
271271
guard asset.tracks.count >= 1 else {

src/Video/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ const NativeVideoCompressor = NativeModules.VideoCompressor;
6868
const Video: VideoCompressorType = {
6969
compress: async (
7070
fileUrl: string,
71-
options?: { bitrate?: number; compressionMethod?: compressionMethod },
71+
options?: {
72+
bitrate?: number;
73+
compressionMethod?: compressionMethod;
74+
maxSize?: number;
75+
},
7276
onProgress?: (progress: number) => void
7377
) => {
7478
const uuid = uuidv4();
@@ -88,10 +92,19 @@ const Video: VideoCompressorType = {
8892
uuid: string;
8993
bitrate?: number;
9094
compressionMethod?: compressionMethod;
95+
maxSize?: number;
9196
} = { uuid };
9297
if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;
93-
if (options?.compressionMethod)
98+
if (options?.compressionMethod) {
9499
modifiedOptions.compressionMethod = options?.compressionMethod;
100+
} else {
101+
modifiedOptions.compressionMethod = 'manual';
102+
}
103+
if (options?.maxSize) {
104+
modifiedOptions.maxSize = options?.maxSize;
105+
} else {
106+
modifiedOptions.maxSize = 640;
107+
}
95108
const result = await NativeVideoCompressor.compress(
96109
fileUrl,
97110
modifiedOptions

0 commit comments

Comments
 (0)