Corrected currentTime & playableDuration when using start & end time
This commit is contained in:
@@ -12,13 +12,17 @@ enum RCTVideoUtils {
|
||||
*
|
||||
* \returns The playable duration of the current player item in seconds.
|
||||
*/
|
||||
static func calculatePlayableDuration(_ player:AVPlayer?) -> NSNumber {
|
||||
static func calculatePlayableDuration(_ player:AVPlayer?, withSource source:VideoSource?) -> NSNumber {
|
||||
guard let player = player,
|
||||
let video:AVPlayerItem = player.currentItem,
|
||||
video.status == AVPlayerItem.Status.readyToPlay else {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (source?.startTime != nil && source?.endTime != nil) {
|
||||
return NSNumber(value: (Float64(source?.endTime ?? 0) - Float64(source?.startTime ?? 0)) / 1000)
|
||||
}
|
||||
|
||||
var effectiveTimeRange:CMTimeRange?
|
||||
for (_, value) in video.loadedTimeRanges.enumerated() {
|
||||
let timeRange:CMTimeRange = value.timeRangeValue
|
||||
@@ -31,6 +35,10 @@ enum RCTVideoUtils {
|
||||
if let effectiveTimeRange = effectiveTimeRange {
|
||||
let playableDuration:Float64 = CMTimeGetSeconds(CMTimeRangeGetEnd(effectiveTimeRange))
|
||||
if playableDuration > 0 {
|
||||
if (source?.startTime != nil) {
|
||||
return NSNumber(value: (playableDuration - Float64(source?.startTime ?? 0) / 1000))
|
||||
}
|
||||
|
||||
return playableDuration as NSNumber
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user