GetSampleAsync Method

MediaStreamSource.GetSampleAsync Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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)

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

Parameters

mediaStreamType
Type: System.Windows.Media.MediaStreamType
The description of the stream that the next sample should come from which will be either Audio or Video.

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

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

Windows Phone will respond to ReportGetSampleCompleted with another GetSampleAsync until the buffer for the given stream is full. Windows Phone may request several samples from one stream before requesting samples from another stream.

Version Notes

Windows Phone

 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.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft