2

I'm trying to understand what is the correct way to check if CMTime is in range. Example:

let's assume we have a video, with a duration of 20 seconds. We split this video into two CMTimeRange.

  • from 0 seconds to 10
  • from 10 seconds to 20

Now, for any given CMTime (for example, the video progress). How can I determine in which CMTimeRange a CMTime Exists?

Roi Mulia
  • 5,626
  • 11
  • 54
  • 105

1 Answers1

2

CMTimeRange has a

func containsTime(_ time: CMTime) -> Bool

method, so you can simply check

if range.containsTime(time) {
    // ...
}

Remark: The documentation seems to be outdated, the global function CMTimeRangeContainsTime() is imported as a member function to Swift.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • Marin R. I know it's it's off topic. But any chance you know if there is a convenient method for Splitting CMTimeRange into multiple chunks? – Roi Mulia Feb 14 '18 at 12:23
  • @RoiMulia: I have no idea. Have a look at https://developer.apple.com/documentation/coremedia/cmtimerange-qts to check if there is anything convenient. – Martin R Feb 14 '18 at 12:25
  • Thanks. I'll try to figure it out. Have a great day Martin! – Roi Mulia Feb 14 '18 at 12:26
  • Hey Martin, I got stuck. I've published a new questions regards this issue: https://stackoverflow.com/questions/48787869/split-cmtimerange-into-multiple-cmtimerange-chunks I'm sure you are busy, but just in case you have some good direction :) Thank you either way! – Roi Mulia Feb 14 '18 at 13:02