Condividi tramite


MediaStreamSource.GetSampleAsync Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

The MediaElement calls this method to ask the MediaStreamSource to prepare the next MediaStreamSample of the requested stream type for the media pipeline. Developers can respond to this method by calling either ReportGetSampleCompleted or ReportGetSampleProgress.

Namespace:  System.Windows.Media
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Protected MustOverride Sub GetSampleAsync ( _
    mediaStreamType As MediaStreamType _
)
protected abstract void GetSampleAsync(
    MediaStreamType mediaStreamType
)

Parameters

Remarks

A developer can respond in one of four ways to a GetSampleAsync call:

  1. Call ReportGetSampleProgress. This informs the MediaElement that the MediaStreamSource is rebuilding its buffer and it will not report samples on any stream until the buffer has has finished rebuilding. Calling ReportGetSampleProgress also permits the MediaElement to transition to the Buffering state, which will pause rendering. A developer can call ReportGetSampleProgress repeatedly to update the download percentage returned by MediaElement.BufferingProgress.

  2. Call ReportGetSampleCompleted with a media sample or an end-of-stream sample for the requested stream. Calling ReportGetSampleCompleted on any stream also indicates buffering is complete for the media and rescinds permission to be in the Buffering state.

  3. Call ErrorOccurred or raise an exception to indicate the media has failed.

  4. Do nothing immediately, but eventually respond in one of the above three ways.

The Silverlight runtime only calls one MediaStreamSource callback at a time. Therefore, developers should quickly exit GetSampleAsync, failing to do so could prevent Silverlight from requesting samples for other streams, reporting state changes, etc.

Silverlight will respond to ReportGetSampleCompleted with another GetSampleAsync until the buffer for the given stream is full. Silverlight may request several samples from one stream before requesting samples from another stream. For more information on buffer management, see the “Buffering Management” section of the Implementing MediaStream Sources.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 Silverlight may call GetSampleAsync for other streams even after a developer has called ReportGetSampleProgress to indicate the MediaStreamSource is rebuilding its buffer. In this scenario, developers should be careful not to call ReportGetSampleCompleted until all buffering is completed.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.