简体   繁体   中英

Check if CMTime is in CMTimeRange

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM