---
title: "loadSegment(forTrackTime:completionHandler:)"
framework: avfoundation
role: symbol
role_heading: Instance Method
path: "avfoundation/avassettrack/loadsegment(fortracktime:completionhandler:)"
---

# loadSegment(forTrackTime:completionHandler:)

Loads a segment with a target time range that contains, or is closest to, the specified track time.

## Declaration

```swift
func loadSegment(forTrackTime trackTime: CMTime, completionHandler: @escaping @Sendable (AVAssetTrackSegment?, (any Error)?) -> Void)
```

```swift
func loadSegment(forTrackTime trackTime: CMTime) async throws -> AVAssetTrackSegment?
```

## Parameters

- `trackTime`: The track time of the segment to load.
- `completionHandler`: A callback that the system invokes after it finishes the loading request. It passes the completion handler the following parameters:

## Discussion

Discussion If the specified track time doesn’t map to a sample presentation time, the system returns the segment with the closest matching time.

## See Also

### Loading track segments

- [segments](avfoundation/avpartialasyncproperty/segments.md)
- [loadSamplePresentationTime(forTrackTime:completionHandler:)](avfoundation/avassettrack/loadsamplepresentationtime(fortracktime:completionhandler:).md)
- [AVAssetTrackSegment](avfoundation/avassettracksegment.md)
