Skip to content

Commit

Permalink
fix(ios): fix startPosition, cropStart and cropEnd to handle float va…
Browse files Browse the repository at this point in the history
…lues correctly (#3589)

* refactor(ios): refactor setPlaybackRange function

* fix(ios): fix props to handle float values correctly

- fix startPosition, cropStart, cropEnd

* refactor(ios): apply lint
  • Loading branch information
YangJonghun committed Mar 22, 2024
1 parent bfb76e6 commit 36bd2e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions ios/Video/DataStructures/VideoSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct VideoSource {
let isAsset: Bool
let shouldCache: Bool
let requestHeaders: [String: Any]?
let startPosition: Int64?
let startPosition: Float64?
let cropStart: Int64?
let cropEnd: Int64?
// Custom Metadata
Expand Down Expand Up @@ -51,9 +51,9 @@ struct VideoSource {
} else {
self.requestHeaders = nil
}
self.startPosition = json["startPosition"] as? Int64
self.cropStart = json["cropStart"] as? Int64
self.cropEnd = json["cropEnd"] as? Int64
self.startPosition = json["startPosition"] as? Float64
self.cropStart = (json["cropStart"] as? Float64).flatMap { Int64(round($0)) }
self.cropEnd = (json["cropEnd"] as? Float64).flatMap { Int64(round($0)) }
self.title = json["title"] as? String
self.subtitle = json["subtitle"] as? String
self.description = json["description"] as? String
Expand Down
14 changes: 7 additions & 7 deletions ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}

if let startPosition = self._source?.startPosition {
self._startPosition = Float64(startPosition) / 1000
self._startPosition = startPosition / 1000
}

#if USE_VIDEO_CACHING
Expand Down Expand Up @@ -398,7 +398,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
self._playerItem = playerItem
self._playerObserver.playerItem = self._playerItem
self.setPreferredForwardBufferDuration(self._preferredForwardBufferDuration)
self.setPlaybackRange(playerItem, withVideoStart: self._source?.cropStart, withVideoEnd: self._source?.cropEnd)
self.setPlaybackRange(playerItem, withCropStart: self._source?.cropStart, withCropEnd: self._source?.cropEnd)
self.setFilter(self._filterName)
if let maxBitRate = self._maxBitRate {
self._playerItem?.preferredPeakBitRate = Double(maxBitRate)
Expand Down Expand Up @@ -740,15 +740,15 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}
}

func setPlaybackRange(_ item: AVPlayerItem!, withVideoStart videoStart: Int64?, withVideoEnd videoEnd: Int64?) {
if videoStart != nil {
let start = CMTimeMake(value: videoStart!, timescale: 1000)
func setPlaybackRange(_ item: AVPlayerItem!, withCropStart cropStart: Int64?, withCropEnd cropEnd: Int64?) {
if let cropStart {
let start = CMTimeMake(value: cropStart, timescale: 1000)
item.reversePlaybackEndTime = start
_pendingSeekTime = Float(CMTimeGetSeconds(start))
_pendingSeek = true
}
if videoEnd != nil {
item.forwardPlaybackEndTime = CMTimeMake(value: videoEnd!, timescale: 1000)
if let cropEnd {
item.forwardPlaybackEndTime = CMTimeMake(value: cropEnd, timescale: 1000)
}
}

Expand Down

0 comments on commit 36bd2e2

Please sign in to comment.