diff --git a/ios/Plugin/TrimSettings.swift b/ios/Plugin/TrimSettings.swift index af29867..7dc344c 100644 --- a/ios/Plugin/TrimSettings.swift +++ b/ios/Plugin/TrimSettings.swift @@ -6,10 +6,14 @@ enum TrimSettingsError: Error { public class TrimSettings: NSObject { - private var startsAt: Double = 0; - private var endsAt: Double = 0; - - init(startsAt: Double, endsAt: Double) throws + private var startsAt: CLong = 0; + private var endsAt: CLong = 0; + + /** + * startsAt: startsAt in miliSeconds + * endsAt: endsAt in miliSeconds + */ + init(startsAt: CLong, endsAt: CLong) throws { if (startsAt < 0) { @@ -22,13 +26,21 @@ public class TrimSettings: NSObject self.startsAt = startsAt; self.endsAt = endsAt; } - - func getStartsAt()->Double + + /** + * Get startsAt in miliSeconds + * @return startsAt in miliSeconds + */ + func getStartsAt()->CLong { return self.startsAt; } - - func setStartsAt(_ startsAt: Double) throws + + /** + * Set startsAt in miliSeconds + * startsAt: startsAt in miliSeconds + */ + func setStartsAt(_ startsAt: CLong) throws { if (startsAt < 0) { @@ -36,13 +48,21 @@ public class TrimSettings: NSObject } self.startsAt = startsAt; } - - func getEndsAt()->Double + + /** + * Get endsAt in miliSeconds + * @return endsAt in miliSeconds + */ + func getEndsAt()->CLong { return self.endsAt; } - - func setEndsAt(_ endsAt: Double) throws + + /** + * Set endsAt in miliSeconds + * endsAt: endsAt in miliSeconds + */ + func setEndsAt(_ endsAt: CLong) throws { if (endsAt < 0) { diff --git a/ios/Plugin/VideoEditor.swift b/ios/Plugin/VideoEditor.swift index 1da2e8f..1a30e3d 100644 --- a/ios/Plugin/VideoEditor.swift +++ b/ios/Plugin/VideoEditor.swift @@ -23,9 +23,9 @@ import UIKit let targetVideoSize:CGSize = calculateTargetVideoSize(sourceVideoSize: mediaSize, transcodeSettings: transcodeSettings); // Trim - let start = CMTimeMakeWithSeconds(Float64(trimSettings.getStartsAt() * 1000), preferredTimescale: 1) + let start = CMTimeMake(value: Int64(trimSettings.getStartsAt()), timescale: 1000) let end = trimSettings.getEndsAt() > 0 - ? CMTimeMakeWithSeconds(Float64(trimSettings.getEndsAt() * 1000), preferredTimescale: 1) + ? CMTimeMake(value: Int64(trimSettings.getEndsAt()), timescale: 1000) : avAsset.duration let duration = min((end - start), (avAsset.duration - start)) let range = CMTimeRangeMake(start: start, duration: duration) diff --git a/ios/Plugin/VideoEditorPlugin.swift b/ios/Plugin/VideoEditorPlugin.swift index 8b8a201..5ec59e8 100644 --- a/ios/Plugin/VideoEditorPlugin.swift +++ b/ios/Plugin/VideoEditorPlugin.swift @@ -22,8 +22,8 @@ public class VideoEditorPlugin: CAPPlugin { do { let trimSettings = try TrimSettings( - startsAt: (trim["startsAt"] ?? 0.0) as! Double, - endsAt: (trim["endsAt"] ?? 0.0) as! Double + startsAt: (trim["startsAt"] ?? 0) as! CLong, + endsAt: (trim["endsAt"] ?? 0) as! CLong ); let transcodeSettings = try TranscodeSettings( diff --git a/src/definitions.ts b/src/definitions.ts index 34bb1dc..a41c554 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -11,15 +11,25 @@ export interface VideoEditorPlugin { export interface EditOptions { path: string; - trim?: { - startsAt?: number; - endsAt?: number; - }; - transcode?: { - height?: number; - width?: number; - keepAspectRatio?: boolean; - }; + trim?: TrimOptions; + transcode?: TranscodeOptions; +} + +export interface TrimOptions { + /** + * StartsAt in milliseconds + */ + startsAt?: number; + /** + * EndsAt in milliseconds + */ + endsAt?: number; +} + +export interface TranscodeOptions { + height?: number; + width?: number; + keepAspectRatio?: boolean; } export interface ThumbnailOptions {