次の方法で共有


File Playback with the Video Control (C++)

 
Microsoft DirectShow 9.0

File Playback with the Video Control (C++)

This topic applies to Windows XP or later.

To play a media file with the Video Control, pass the file name to the IMSVidCtl::View method:

CComVariant var(OLESTR("C:\\Example.avi"));
hr = pVidControl->View(&var);

If the method call succeeds, the active input device is the MSVidFilePlaybackDevice object, which exposes the IMSVidFilePlayback interface. (The IMSVidFilePlayback interface inherits IMSVidPlayback.) You can use this interface to seek in the file, change the playback rate, or step through the file.

The following code shows how to obtain the input device and query for the playback interface:

CComPtr<IMSVidInputDevice> pInputDevice;
HRESULT hr = pVidControl->get_InputActive(&pInputDevice);
if (SUCCEEDED(hr))
{
    CComQIPtr<IMSVidFilePlayback> pFilePlayback(pInputDevice);
    if (pFilePlayback != NULL)
    {
         /* The file playback device is the active input. Call
            IMSVidFilePlayback methods to control the device. */
    }
}

To seek, call the put_CurrentPosition method:

hr = pFilePlayback->put_CurrentPosition(200); // 2 msec

The default units are hundredths of seconds. You can change this to frames by calling the IMSVidPlayback::put_PositionMode method.

To change the playback rate, call the put_Rate method:

hr = pFilePlayback->put_Rate(2.0); // Twice normal speed.

To step forward frame-by-frame, first call get_CanStep to determine whether the source file supports frame stepping. If so, call the Step method to step forward in the file:

VARIANT_BOOL fCan;
hr = pFilePlayback->get_CanStep(VARIANT_FALSE, &fCan);
if (SUCCEEDED(hr)) && (fCan == VARIANT_TRUE))
{
    hr = pFilePlayback->Step(2);  // Step two frames.
}