IWMSyncReader::GetNextSample method

The GetNextSample method retrieves the next sample from the file.


HRESULT GetNextSample(
  WORD       wStreamNum,
  INSSBuffer **ppSample,
  QWORD      *pcnsSampleTime,
  QWORD      *pcnsDuration,
  DWORD      *pdwFlags,
  DWORD      *pdwOutputNum,
  WORD       *pwStreamNum



WORD containing the stream number for which you would like a sample. If you pass zero, the next sample in the file is returned, regardless of stream number.


Pointer to a buffer that receives the sample. Set to NULL to retrieve the sample time without getting the sample. If set to NULL, pcnsDuration and pdwFlags must both be set to NULL as well.


Pointer to a QWORD variable that receives the sample time in 100-nanosecond units.


Pointer to QWORD variable that receives the duration of the sample in 100-nanosecond units.


Pointer to a DWORD containing one or more of the following flags.

Flag Description
No flag set None of the conditions for the other flags applies. For example, a delta frame in most cases would not have any flags set for it.
WM_SF_CLEANPOINT Indicates that the sample does not require any other samples to be decompressed. All audio samples and all video samples that are key frames are cleanpoints.
WM_SF_DISCONTINUITY The data stream has a gap in it, which could be due to a seek, a network loss, or other reason. This can be useful extra information for an application such as a codec or renderer. The flag is set on the first piece of data following the gap.
WM_SF_DATALOSS Some data has been lost between the previous sample and the sample with this flag set.


Pointer to a DWORD that receives the output number.


Pointer to a WORD that receives the stream number.

Return value

The method returns an HRESULT. Possible values include, but are not limited to, those in the following table.

Return code Description
The method succeeded.
All the samples in the file have been read.
A problem occurred with a call within the method.
wStreamNum specifies a stream number that is not valid.


pcnsSampleTime is NULL


ppSample, pcnsDuration, or pdwFlags is NULL, but one or both of the others are not.


wStreamNum is 0 and both pdwOutputNum and pwStreamNum are NULL.

No file is open and ready for reading by the synchronous reader.


wStreamNum specifies a stream number that is turned off (not selected for reading).


Both compressed and uncompressed samples are delivered by this method, depending upon whether you have called SetReadStreamSamples for the streams in the file. This is the only method to retrieve samples using the synchronous reader.

To begin receiving samples from anywhere in the file other than the beginning, you must first specify a range for playback. To specify a playback range based on presentation times, use the SetRange method. To set a range using frame numbers, use the SetRangeByFrame method. When you have received all of the samples in the file, or in the range if you specified one, the next call made to GetNextSample returns NS_E_NO_MORE_SAMPLES.

The timeline is presentation time if no output setting is specified. To get early delivery for a stream, use SetOutputSetting.

You can call GetNextSample in one of three ways:

  • If you pass a non-zero value as wStreamNum, you will get the next sample for the specified stream number. In this case, you can pass NULL for both pdwOutputNum and pwStreamNum.
  • If you pass zero as wStreamNum, and are using output numbers, you can pass NULL for pwStreamNum. In this case you must pass a valid address for pdwOutputNum.
  • If you pass zero as wStreamNum, and are not using output numbers, you can pass NULL for pdwOutputNum. In this case you must pass a valid address for pwStreamNum.
You can also use GetNextSample to retrieve precise times for video frames when reading compressed data. For more information, see To Retrieve Accurate Presentation Times for Compressed Samples by Frame.
Note  To ensure that you get correct sample durations from this method, you must configure the output for the stream. Call the SetOutputSetting method to set the g_wszVideoSampleDurations setting to TRUE. Subsequent calls to GetNextSample will return correct sample durations.


Minimum supported client Windows 2000 Professional [desktop apps only],Windows Media Format 9 Series SDK, or later versions of the SDK
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header wmsdkidl.h (include Wmsdk.h)
Library Wmvcore.lib; WMStubDRM.lib (if you use DRM)

See also

INSSBuffer Interface

IWMSyncReader Interface