<!--
{
  "availability" : [
    "macOS: 14.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MediaExtension",
  "identifier" : "/documentation/MediaExtension/MESampleCursor/loadSampleBufferContainingSamples(to:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "MediaExtension"
    ],
    "preciseIdentifier" : "c:objc(pl)MESampleCursor(im)loadSampleBufferContainingSamplesToEndCursor:completionHandler:"
  },
  "title" : "loadSampleBufferContainingSamples(to:completionHandler:)"
}
-->

# loadSampleBufferContainingSamples(to:completionHandler:)

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

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

## 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

Plugin format readers that don’t implement [`sampleLocation()`](/documentation/MediaExtension/MESampleCursor/sampleLocation()) or that always load sample data to answer cursor queries need to implement this method. If a plug-in format reader implements [`sampleLocation()`](/documentation/MediaExtension/MESampleCursor/sampleLocation()), implementing [`loadSampleBufferContainingSamples(to:completionHandler:)`](/documentation/MediaExtension/MESampleCursor/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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)