react-native-video-trim 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -33
- package/android/src/main/AndroidManifest.xml +13 -0
- package/android/src/main/java/com/videotrim/VideoTrimModule.java +282 -75
- package/android/src/main/java/com/videotrim/enums/ErrorCode.java +10 -0
- package/android/src/main/java/com/videotrim/interfaces/VideoTrimListener.java +4 -1
- package/android/src/main/java/com/videotrim/utils/MediaMetadataUtil.java +75 -0
- package/android/src/main/java/com/videotrim/utils/StorageUtil.java +2 -2
- package/android/src/main/java/com/videotrim/utils/VideoTrimmerUtil.java +26 -16
- package/android/src/main/java/com/videotrim/widgets/VideoTrimmerView.java +310 -81
- package/android/src/main/res/drawable/airpodsmax.xml +19 -0
- package/android/src/main/res/drawable/exclamationmark_triangle_fill.xml +15 -0
- package/android/src/main/res/drawable/thumb_container_bg.xml +8 -0
- package/android/src/main/res/layout/video_trimmer_view.xml +71 -4
- package/android/src/main/res/xml/file_paths.xml +5 -0
- package/ios/AssetLoader.swift +99 -0
- package/ios/ErrorCode.swift +16 -0
- package/ios/ProgressAlertController.swift +100 -0
- package/ios/VideoTrim.mm +4 -2
- package/ios/VideoTrim.swift +472 -177
- package/ios/VideoTrimmer.swift +16 -10
- package/ios/VideoTrimmerViewController.swift +191 -22
- package/lib/commonjs/index.js +25 -55
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +24 -55
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +215 -9
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +229 -66
- package/android/src/main/java/iknow/android/utils/BuildConfig.java +0 -18
- package/android/src/main/java/iknow/android/utils/DateUtil.java +0 -64
|
@@ -3,18 +3,59 @@
|
|
|
3
3
|
android:layout_width="match_parent"
|
|
4
4
|
android:layout_height="match_parent"
|
|
5
5
|
android:orientation="vertical">
|
|
6
|
+
<FrameLayout
|
|
7
|
+
android:id="@+id/headerView"
|
|
8
|
+
android:layout_width="match_parent"
|
|
9
|
+
android:layout_height="wrap_content"
|
|
10
|
+
android:minHeight="50dp"
|
|
11
|
+
android:background="@android:color/black"
|
|
12
|
+
android:visibility="gone"
|
|
13
|
+
>
|
|
14
|
+
<TextView
|
|
15
|
+
android:id="@+id/headerText"
|
|
16
|
+
android:layout_width="wrap_content"
|
|
17
|
+
android:layout_height="match_parent"
|
|
18
|
+
android:layout_gravity="center"
|
|
19
|
+
android:clickable="true"
|
|
20
|
+
android:focusable="true"
|
|
21
|
+
android:text="Header text"
|
|
22
|
+
android:textColor="@android:color/white"
|
|
23
|
+
android:textSize="16dp" />
|
|
24
|
+
</FrameLayout>
|
|
6
25
|
|
|
7
26
|
<RelativeLayout
|
|
8
27
|
android:layout_width="match_parent"
|
|
9
28
|
android:layout_height="match_parent"
|
|
10
29
|
android:layout_above="@+id/layout"
|
|
30
|
+
android:layout_below="@+id/headerView"
|
|
11
31
|
android:background="@android:color/black"
|
|
12
32
|
android:gravity="center">
|
|
13
33
|
|
|
14
34
|
<VideoView
|
|
15
35
|
android:id="@+id/video_loader"
|
|
16
36
|
android:layout_width="match_parent"
|
|
17
|
-
android:layout_height="match_parent"
|
|
37
|
+
android:layout_height="match_parent"
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
<FrameLayout
|
|
41
|
+
android:id="@+id/audioBannerView"
|
|
42
|
+
android:layout_width="match_parent"
|
|
43
|
+
android:layout_height="match_parent"
|
|
44
|
+
android:layout_marginStart="50dp"
|
|
45
|
+
android:layout_marginTop="50dp"
|
|
46
|
+
android:layout_marginEnd="50dp"
|
|
47
|
+
android:layout_marginBottom="50dp"
|
|
48
|
+
android:padding="50dp"
|
|
49
|
+
android:visibility="gone">
|
|
50
|
+
|
|
51
|
+
<ImageView
|
|
52
|
+
android:layout_width="match_parent"
|
|
53
|
+
android:layout_height="match_parent"
|
|
54
|
+
android:layout_gravity="center"
|
|
55
|
+
android:contentDescription="Airpods Max"
|
|
56
|
+
android:src="@drawable/airpodsmax"
|
|
57
|
+
/>
|
|
58
|
+
</FrameLayout>
|
|
18
59
|
|
|
19
60
|
</RelativeLayout>
|
|
20
61
|
|
|
@@ -38,7 +79,8 @@
|
|
|
38
79
|
android:layout_height="match_parent"
|
|
39
80
|
android:layout_marginHorizontal="20dp"
|
|
40
81
|
android:orientation="horizontal"
|
|
41
|
-
android:padding="4dp"
|
|
82
|
+
android:padding="4dp"
|
|
83
|
+
/>
|
|
42
84
|
|
|
43
85
|
<RelativeLayout
|
|
44
86
|
android:id="@+id/trimmerContainerWrapper"
|
|
@@ -201,7 +243,30 @@
|
|
|
201
243
|
android:layout_gravity="center"
|
|
202
244
|
android:padding="12dp"
|
|
203
245
|
android:src="@drawable/play_fill"
|
|
204
|
-
android:tint="@color/white"
|
|
246
|
+
android:tint="@color/white"
|
|
247
|
+
android:visibility="gone"
|
|
248
|
+
/>
|
|
249
|
+
|
|
250
|
+
<ImageView
|
|
251
|
+
android:id="@+id/failToLoadBtn"
|
|
252
|
+
android:layout_width="wrap_content"
|
|
253
|
+
android:layout_height="match_parent"
|
|
254
|
+
android:layout_gravity="center"
|
|
255
|
+
android:padding="12dp"
|
|
256
|
+
android:src="@drawable/exclamationmark_triangle_fill"
|
|
257
|
+
android:tint="@color/trim_color"
|
|
258
|
+
android:visibility="gone"
|
|
259
|
+
/>
|
|
260
|
+
|
|
261
|
+
<ProgressBar
|
|
262
|
+
android:id="@+id/loadingIndicator"
|
|
263
|
+
style="?android:attr/progressBarStyle"
|
|
264
|
+
android:layout_width="wrap_content"
|
|
265
|
+
android:layout_height="wrap_content"
|
|
266
|
+
android:layout_gravity="center"
|
|
267
|
+
android:padding="10dp"
|
|
268
|
+
android:indeterminateTint="@color/white"
|
|
269
|
+
/>
|
|
205
270
|
|
|
206
271
|
<TextView
|
|
207
272
|
android:id="@+id/saveBtn"
|
|
@@ -212,7 +277,9 @@
|
|
|
212
277
|
android:padding="10dp"
|
|
213
278
|
android:text="@string/save"
|
|
214
279
|
android:textColor="#2196F3"
|
|
215
|
-
android:textSize="16dp"
|
|
280
|
+
android:textSize="16dp"
|
|
281
|
+
android:visibility="gone"
|
|
282
|
+
/>
|
|
216
283
|
|
|
217
284
|
</FrameLayout>
|
|
218
285
|
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AssetLoader.swift
|
|
3
|
+
// react-native-video-trim
|
|
4
|
+
//
|
|
5
|
+
// Created by Duc Trung Mai on 7/27/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import AVFoundation
|
|
9
|
+
|
|
10
|
+
protocol AssetLoaderDelegate: AnyObject {
|
|
11
|
+
func assetLoader(_ loader: AssetLoader, didFailWithError error: Error, forKey key: String)
|
|
12
|
+
func assetLoaderDidSucceed(_ loader: AssetLoader)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class AssetLoader: NSObject {
|
|
16
|
+
var asset: AVURLAsset?
|
|
17
|
+
weak var delegate: AssetLoaderDelegate?
|
|
18
|
+
|
|
19
|
+
func loadAsset(url: URL, isVideoType: Bool) {
|
|
20
|
+
// Creating AVURLAsset (not blocking the main thread)
|
|
21
|
+
asset = AVURLAsset(url: url, options: [AVURLAssetPreferPreciseDurationAndTimingKey: true])
|
|
22
|
+
let keys = ["duration", "tracks"]
|
|
23
|
+
|
|
24
|
+
// Asynchronous property loading
|
|
25
|
+
asset?.loadValuesAsynchronously(forKeys: keys) {
|
|
26
|
+
DispatchQueue.main.async {
|
|
27
|
+
self.assetLoaded(isVideoType: isVideoType)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private func assetLoaded(isVideoType: Bool) {
|
|
33
|
+
guard let asset = asset else { return }
|
|
34
|
+
|
|
35
|
+
let keys = ["duration", "tracks"]
|
|
36
|
+
for key in keys {
|
|
37
|
+
var error: NSError?
|
|
38
|
+
let status = asset.statusOfValue(forKey: key, error: &error)
|
|
39
|
+
|
|
40
|
+
if status == .failed {
|
|
41
|
+
if let error = error {
|
|
42
|
+
delegate?.assetLoader(self, didFailWithError: error, forKey: key)
|
|
43
|
+
}
|
|
44
|
+
return
|
|
45
|
+
} else if status == .cancelled {
|
|
46
|
+
delegate?.assetLoader(self, didFailWithError: NSError(domain: "AssetLoader", code: -1, userInfo: [NSLocalizedDescriptionKey: "\(key) loading was cancelled"]), forKey: key)
|
|
47
|
+
return
|
|
48
|
+
} else if status != .loaded {
|
|
49
|
+
delegate?.assetLoader(self, didFailWithError: NSError(domain: "AssetLoader", code: -1, userInfo: [NSLocalizedDescriptionKey: "\(key) is in an unknown state"]), forKey: key)
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if isVideoType {
|
|
55
|
+
// Process the tracks to load the remaining properties
|
|
56
|
+
self.processAssetTracks()
|
|
57
|
+
} else {
|
|
58
|
+
delegate?.assetLoaderDidSucceed(self)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private func processAssetTracks() {
|
|
63
|
+
guard let asset = asset else { return }
|
|
64
|
+
|
|
65
|
+
let videoTracks = asset.tracks(withMediaType: .video)
|
|
66
|
+
guard let videoTrack = videoTracks.first else {
|
|
67
|
+
delegate?.assetLoader(self, didFailWithError: NSError(domain: "AssetLoader", code: -1, userInfo: [NSLocalizedDescriptionKey: "No video tracks found"]), forKey: "tracks")
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let trackKeys = ["naturalSize", "preferredTransform"]
|
|
72
|
+
videoTrack.loadValuesAsynchronously(forKeys: trackKeys) {
|
|
73
|
+
DispatchQueue.main.async {
|
|
74
|
+
self.trackPropertiesLoaded(track: videoTrack)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private func trackPropertiesLoaded(track: AVAssetTrack) {
|
|
80
|
+
var error: NSError?
|
|
81
|
+
|
|
82
|
+
let naturalSizeStatus = track.statusOfValue(forKey: "naturalSize", error: &error)
|
|
83
|
+
let preferredTransformStatus = track.statusOfValue(forKey: "preferredTransform", error: &error)
|
|
84
|
+
|
|
85
|
+
if naturalSizeStatus == .loaded, preferredTransformStatus == .loaded {
|
|
86
|
+
let naturalSize = track.naturalSize
|
|
87
|
+
let preferredTransform = track.preferredTransform
|
|
88
|
+
|
|
89
|
+
print("Natural size: \(naturalSize)")
|
|
90
|
+
print("Preferred transform: \(preferredTransform)")
|
|
91
|
+
delegate?.assetLoaderDidSucceed(self)
|
|
92
|
+
} else {
|
|
93
|
+
if let error = error {
|
|
94
|
+
let failedKey = naturalSizeStatus != .loaded ? "naturalSize" : "preferredTransform"
|
|
95
|
+
delegate?.assetLoader(self, didFailWithError: error, forKey: failedKey)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ErrorCode.swift
|
|
3
|
+
// react-native-video-trim
|
|
4
|
+
//
|
|
5
|
+
// Created by ByteDance on 7/27/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
enum ErrorCode: String {
|
|
11
|
+
case trimmingFailed = "TRIMMING_FAILED"
|
|
12
|
+
case failToLoadMedia = "FAIL_TO_LOAD_MEDIA"
|
|
13
|
+
case failToSaveToPhoto = "FAIL_TO_SAVE_TO_PHOTO"
|
|
14
|
+
case failToShare = "FAIL_TO_SHARE"
|
|
15
|
+
case noPhotoPermission = "NO_PHOTO_PERMISSION"
|
|
16
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ProgressAlertController.swift
|
|
3
|
+
// react-native-video-trim
|
|
4
|
+
//
|
|
5
|
+
// Created by Duc Trung Mai on 8/18/24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import UIKit
|
|
9
|
+
|
|
10
|
+
class ProgressAlertController: UIViewController {
|
|
11
|
+
var onDismiss: (() -> Void)?
|
|
12
|
+
|
|
13
|
+
private let titleLabel = UILabel()
|
|
14
|
+
private let progressBar = UIProgressView(progressViewStyle: .default)
|
|
15
|
+
private let actionButton = UIButton(type: .system)
|
|
16
|
+
|
|
17
|
+
override func viewDidLoad() {
|
|
18
|
+
super.viewDidLoad()
|
|
19
|
+
|
|
20
|
+
setupBackground()
|
|
21
|
+
setupAlertView()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private func setupBackground() {
|
|
25
|
+
view.backgroundColor = UIColor.black.withAlphaComponent(0.4)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private func setupAlertView() {
|
|
29
|
+
let alertView = UIView()
|
|
30
|
+
alertView.backgroundColor = UIColor(red: 28/255, green: 28/255, blue: 30/255, alpha: 1.0)
|
|
31
|
+
alertView.layer.cornerRadius = 12
|
|
32
|
+
alertView.translatesAutoresizingMaskIntoConstraints = false
|
|
33
|
+
view.addSubview(alertView)
|
|
34
|
+
|
|
35
|
+
// AlertView Constraints
|
|
36
|
+
NSLayoutConstraint.activate([
|
|
37
|
+
alertView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
|
38
|
+
alertView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
|
|
39
|
+
alertView.widthAnchor.constraint(equalToConstant: 270)
|
|
40
|
+
])
|
|
41
|
+
|
|
42
|
+
// Title Label
|
|
43
|
+
titleLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
44
|
+
titleLabel.textAlignment = .center
|
|
45
|
+
titleLabel.font = UIFont.systemFont(ofSize: 18)
|
|
46
|
+
titleLabel.numberOfLines = 0
|
|
47
|
+
titleLabel.textColor = .white
|
|
48
|
+
alertView.addSubview(titleLabel)
|
|
49
|
+
|
|
50
|
+
// Progress Bar
|
|
51
|
+
progressBar.translatesAutoresizingMaskIntoConstraints = false
|
|
52
|
+
alertView.addSubview(progressBar)
|
|
53
|
+
|
|
54
|
+
// Action Button
|
|
55
|
+
actionButton.setTitle("Cancel", for: .normal)
|
|
56
|
+
actionButton.setTitleColor(.systemPink, for: .normal)
|
|
57
|
+
actionButton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
|
|
58
|
+
actionButton.addTarget(self, action: #selector(dismissAlert), for: .touchUpInside)
|
|
59
|
+
actionButton.translatesAutoresizingMaskIntoConstraints = false
|
|
60
|
+
actionButton.isHidden = true
|
|
61
|
+
alertView.addSubview(actionButton)
|
|
62
|
+
|
|
63
|
+
// Constraints for titleLabel, progressBar, and actionButton
|
|
64
|
+
NSLayoutConstraint.activate([
|
|
65
|
+
titleLabel.topAnchor.constraint(equalTo: alertView.topAnchor, constant: 16),
|
|
66
|
+
titleLabel.leadingAnchor.constraint(equalTo: alertView.leadingAnchor, constant: 16),
|
|
67
|
+
titleLabel.trailingAnchor.constraint(equalTo: alertView.trailingAnchor, constant: -16),
|
|
68
|
+
|
|
69
|
+
progressBar.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 16),
|
|
70
|
+
progressBar.leadingAnchor.constraint(equalTo: alertView.leadingAnchor, constant: 16),
|
|
71
|
+
progressBar.trailingAnchor.constraint(equalTo: alertView.trailingAnchor, constant: -16),
|
|
72
|
+
|
|
73
|
+
actionButton.topAnchor.constraint(equalTo: progressBar.bottomAnchor, constant: 16),
|
|
74
|
+
actionButton.bottomAnchor.constraint(equalTo: alertView.bottomAnchor, constant: -16),
|
|
75
|
+
actionButton.centerXAnchor.constraint(equalTo: alertView.centerXAnchor)
|
|
76
|
+
])
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@objc private func dismissAlert() {
|
|
80
|
+
self.onDismiss?()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
func setTitle(_ text: String) {
|
|
84
|
+
titleLabel.text = text
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
func setCancelTitle(_ text: String) {
|
|
88
|
+
actionButton.setTitle(text, for: .normal)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
func setProgress(_ progress: Float) {
|
|
92
|
+
progressBar.setProgress(progress, animated: true)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
func showCancelBtn() {
|
|
96
|
+
// Ensure that the button is properly added to the view hierarchy and that the layout has been updated before hiding the button
|
|
97
|
+
view.layoutIfNeeded()
|
|
98
|
+
actionButton.isHidden = false
|
|
99
|
+
}
|
|
100
|
+
}
|
package/ios/VideoTrim.mm
CHANGED
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
@interface RCT_EXTERN_MODULE(VideoTrim, RCTEventEmitter)
|
|
5
5
|
|
|
6
6
|
RCT_EXTERN_METHOD(showEditor:(NSString*)uri withConfig:(NSDictionary *)config)
|
|
7
|
-
RCT_EXTERN_METHOD(isValidVideo:(NSString*)uri withResolver:(RCTPromiseResolveBlock)resolve
|
|
8
|
-
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
9
7
|
RCT_EXTERN_METHOD(listFiles:(RCTPromiseResolveBlock)resolve
|
|
10
8
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
11
9
|
RCT_EXTERN_METHOD(cleanFiles:(RCTPromiseResolveBlock)resolve
|
|
12
10
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
13
11
|
RCT_EXTERN_METHOD(deleteFile:(NSString*)uri withResolver:(RCTPromiseResolveBlock)resolve
|
|
14
12
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
13
|
+
RCT_EXTERN_METHOD(closeEditor:(RCTPromiseResolveBlock)resolve
|
|
14
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
15
|
+
RCT_EXTERN_METHOD(isValidFile:(NSString*)uri withResolver:(RCTPromiseResolveBlock)resolve
|
|
16
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
15
17
|
@end
|