react-native-video-trim 1.0.22 → 1.0.23
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.
|
@@ -48,7 +48,6 @@ class VideoTrimmerViewController: UIViewController {
|
|
|
48
48
|
var isSeekInProgress: Bool = false // Marker
|
|
49
49
|
private var chaseTime = CMTime.zero
|
|
50
50
|
private var preferredFrameRate: Float = 23.98
|
|
51
|
-
|
|
52
51
|
|
|
53
52
|
// MARK: - Input
|
|
54
53
|
@objc private func didBeginTrimmingFromStart(_ sender: VideoTrimmer) {
|
|
@@ -133,6 +132,9 @@ class VideoTrimmerViewController: UIViewController {
|
|
|
133
132
|
player.removeTimeObserver(token)
|
|
134
133
|
timeObserverToken = nil
|
|
135
134
|
}
|
|
135
|
+
// Remove observer
|
|
136
|
+
NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: player.currentItem)
|
|
137
|
+
|
|
136
138
|
playerController.player = nil
|
|
137
139
|
playerController.dismiss(animated: false, completion: nil)
|
|
138
140
|
}
|
|
@@ -259,6 +261,15 @@ class VideoTrimmerViewController: UIViewController {
|
|
|
259
261
|
playerController.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
|
|
260
262
|
playerController.view.bottomAnchor.constraint(equalTo: trimmer.topAnchor, constant: -16)
|
|
261
263
|
])
|
|
264
|
+
|
|
265
|
+
// Add observer for the end of playback
|
|
266
|
+
NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying), name: .AVPlayerItemDidPlayToEndTime, object: player.currentItem)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
@objc private func playerDidFinishPlaying(note: NSNotification) {
|
|
270
|
+
// Directly set the play icon
|
|
271
|
+
// the reason in at this time player.timeControlStatus == .playing still returns true
|
|
272
|
+
playBtn.setImage(self.playIcon, for: .normal)
|
|
262
273
|
}
|
|
263
274
|
|
|
264
275
|
private func setupTimeObserver() {
|
|
@@ -292,29 +303,29 @@ class VideoTrimmerViewController: UIViewController {
|
|
|
292
303
|
public func seek(to time: CMTime) {
|
|
293
304
|
seekSmoothlyToTime(newChaseTime: time)
|
|
294
305
|
}
|
|
295
|
-
|
|
306
|
+
|
|
296
307
|
private func seekSmoothlyToTime(newChaseTime: CMTime) {
|
|
297
308
|
if CMTimeCompare(newChaseTime, chaseTime) != 0 {
|
|
298
309
|
chaseTime = newChaseTime
|
|
299
|
-
|
|
310
|
+
|
|
300
311
|
if !isSeekInProgress {
|
|
301
312
|
trySeekToChaseTime()
|
|
302
313
|
}
|
|
303
314
|
}
|
|
304
315
|
}
|
|
305
|
-
|
|
316
|
+
|
|
306
317
|
private func trySeekToChaseTime() {
|
|
307
318
|
guard player?.status == .readyToPlay else { return }
|
|
308
319
|
actuallySeekToTime()
|
|
309
320
|
}
|
|
310
|
-
|
|
321
|
+
|
|
311
322
|
private func actuallySeekToTime() {
|
|
312
323
|
isSeekInProgress = true
|
|
313
324
|
let seekTimeInProgress = chaseTime
|
|
314
|
-
|
|
325
|
+
|
|
315
326
|
player?.seek(to: seekTimeInProgress, toleranceBefore: .zero, toleranceAfter: .zero) { [weak self] _ in
|
|
316
327
|
guard let `self` = self else { return }
|
|
317
|
-
|
|
328
|
+
|
|
318
329
|
if CMTimeCompare(seekTimeInProgress, self.chaseTime) == 0 {
|
|
319
330
|
self.isSeekInProgress = false
|
|
320
331
|
} else {
|