Passaggio 7: Controlli di trasporto
[La funzionalità associata a questa pagina, DirectShow, è una funzionalità legacy. È stata sostituita da MediaPlayer, IMFMediaEngine e Audio/Video Capture in Media Foundation. Queste funzionalità sono state ottimizzate per Windows 10 e Windows 11. Microsoft consiglia vivamente che il nuovo codice usi MediaPlayer, IMFMediaEngine e Audio/Video Capture in Media Foundation invece di DirectShow, quando possibile. Microsoft suggerisce che il codice esistente che usa le API legacy venga riscritto per usare le nuove API, se possibile.
Questo argomento è il passaggio 7 dell'esercitazione Riproduzione audio/video in DirectShow. Il codice completo è illustrato nell'argomento Esempio di riproduzione DirectShow.
L'ultimo passaggio consiste nell'aggiungere controlli di trasporto (riproduzione, sospensione e arresto). Per riprodurre il file, chiama IMediaControl::Run.
HRESULT DShowPlayer::Play()
{
if (m_state != STATE_PAUSED && m_state != STATE_STOPPED)
{
return VFW_E_WRONG_STATE;
}
HRESULT hr = m_pControl->Run();
if (SUCCEEDED(hr))
{
m_state = STATE_RUNNING;
}
return hr;
}
Per sospendere, chiama IMediaControl::P ause.
HRESULT DShowPlayer::Pause()
{
if (m_state != STATE_RUNNING)
{
return VFW_E_WRONG_STATE;
}
HRESULT hr = m_pControl->Pause();
if (SUCCEEDED(hr))
{
m_state = STATE_PAUSED;
}
return hr;
}
Per arrestare, chiama IMediaControl::Stop.
HRESULT DShowPlayer::Stop()
{
if (m_state != STATE_RUNNING && m_state != STATE_PAUSED)
{
return VFW_E_WRONG_STATE;
}
HRESULT hr = m_pControl->Stop();
if (SUCCEEDED(hr))
{
m_state = STATE_STOPPED;
}
return hr;
}
Argomenti correlati