---
title: "loadSampleBufferContainingSamples(to:completionHandler:)"
framework: MediaExtension
role: symbol
role_heading: Instance Method
platforms: [macOS 14.0+]
path: "mediaextension/mesamplecursor/loadsamplebuffercontainingsamples(to:completionhandler:)"
---

# loadSampleBufferContainingSamples(to:completionHandler:)

Builds a sample buffer that contains the samples at the cursor that you specify.

## Declaration

```swift
optional func loadSampleBufferContainingSamples(to endSampleCursor: (any MESampleCursor)?, completionHandler: @escaping @Sendable (CMSampleBuffer?, (any Error)?) -> Void)
```

```swift
optional func loadSampleBufferContainingSamples(to endSampleCursor: (any MESampleCursor)?) async throws -> CMSampleBuffer
```

## Parameters

- `endSampleCursor`: If not nil, this cursor indicates the last sample that the new sample buffer should contain.
- `completionHandler`: The completion block to execute when the load operation finishes.

## Discussion

Discussion Plugin format readers that don’t implement sampleLocation() or that always load sample data to answer cursor queries need to implement this method. If a plug-in format reader implements sampleLocation(), implementing loadSampleBufferContainingSamples(to:completionHandler:) is optional. If there’s no sample data between the sample cursor and endSampleCursor, the sample buffer is empty. If an error occurs, the sample buffer is nil. important: If there’s a change of format description between the sample cursor and endSampleCursor, the returned sample buffer needs to contain only the contiguous samples with the same format description as the first sample.

## See Also

### Sending samples to a pipeline

- [chunkDetails()](mediaextension/mesamplecursor/chunkdetails().md)
- [sampleLocation()](mediaextension/mesamplecursor/samplelocation().md)
