Quantcast
Channel: Media Foundation Development for Windows Desktop forum
Viewing all articles
Browse latest Browse all 1079

Confused about how to seek using IMFSourceReader:: SetCurrentPosition

$
0
0

I'm using IMFSourceReader to grab samples on an audio file.

I want to be able to seek anywhere in the audio timeline.

I have this function which sets the position:

void Seek(Windows::Foundation::TimeSpan position)
{
    HRESULT hr;

    PROPVARIANT var;
    hr = InitPropVariantFromInt64(position.Duration, &var);
    ThrowIfFailed(hr);
    
    hr = m_pSourceReader->SetCurrentPosition(GUID_NULL, var);
    PropVariantClear(&var);

    ThrowIfFailed(hr);
}

the position is tied to a slider between 0 and the audio max time obtained from:

Windows::Foundation::TimeSpan GetDuration()
{
    PROPVARIANT var;
    PropVariantInit(&var);

    HRESULT hr = m_pSourceReader->GetPresentationAttribute(MF_SOURCE_READER_MEDIASOURCE, MF_PD_DURATION, &var);
    ThrowIfFailed(hr);

    LONGLONG hnsDuration;
    hr = PropVariantToInt64(var, &hnsDuration);
    ThrowIfFailed(hr);

    PropVariantClear(&var);

    Windows::Foundation::TimeSpan timeSpan;
    timeSpan.Duration = hnsDuration;
    return timeSpan;
}

whenever I change the slider position it calls Seek(slider.Position.ToTimeSpan()) (in pseudo code)

But it doesn't work.

the next sample I read using

m_pSourceReader->ReadSample((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, NULL, &dwFlags, &_timeStamp, &pSample);

_timeStamp : does not reflect the seeked position.

What am I missing here ?

thanks!


Viewing all articles
Browse latest Browse all 1079

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>