Contents

insertTimeRange(_:of:at:completionHandler:)

Inserts all tracks of an asset for a time range into a composition.

Declaration

func insertTimeRange(_ timeRange: CMTimeRange, of asset: AVAsset, at startTime: CMTime, completionHandler: @escaping  @Sendable ((any Error)?) -> Void)

Parameters

  • timeRange:

    The time range of the asset’s tracks to insert into the composition.

  • asset:

    The source asset that contains the tracks to insert.

  • startTime:

    A time in the composition to present the inserted tracks.

  • completionHandler:

    A callback the system invokes when the insertion is complete. If an error occurs, the system passes the callback an error object that describes the failure.

Discussion

If necessary, a composition adds new tracks to ensure that it inserts all tracks in the source asset for the time range. Inserting a time range pushes out existing content at the specified start time by the time range’s duration.

The composition presents the media data for the inserted time range at its natural duration and rate. You can scale it to a different duration, which changes the presentation rate, by calling scaleTimeRange(_:toDuration:).

See Also

Managing time ranges