playback.h
[与此页面关联的功能 DirectShow 是一项旧功能。 它已被 MediaPlayer、 IMFMediaEngine 和 媒体基金会中的音频/视频捕获取代。 这些功能已针对Windows 10和Windows 11进行了优化。 Microsoft 强烈建议新代码尽可能使用 MediaPlayer、 IMFMediaEngine 和 Media Foundation 中的音频/视频捕获 ,而不是 DirectShow。 如果可能,Microsoft 建议重写使用旧 API 的现有代码以使用新 API。]
本主题包含 DirectShow 中的音频/视频播放教程的代码。
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
#pragma once
class CVideoRenderer;
enum PlaybackState
{
STATE_NO_GRAPH,
STATE_RUNNING,
STATE_PAUSED,
STATE_STOPPED,
};
const UINT WM_GRAPH_EVENT = WM_APP + 1;
typedef void (CALLBACK *GraphEventFN)(HWND hwnd, long eventCode, LONG_PTR param1, LONG_PTR param2);
class DShowPlayer
{
public:
DShowPlayer(HWND hwnd);
~DShowPlayer();
PlaybackState State() const { return m_state; }
HRESULT OpenFile(PCWSTR pszFileName);
HRESULT Play();
HRESULT Pause();
HRESULT Stop();
BOOL HasVideo() const;
HRESULT UpdateVideoWindow(const LPRECT prc);
HRESULT Repaint(HDC hdc);
HRESULT DisplayModeChanged();
HRESULT HandleGraphEvent(GraphEventFN pfnOnGraphEvent);
private:
HRESULT InitializeGraph();
void TearDownGraph();
HRESULT CreateVideoRenderer();
HRESULT RenderStreams(IBaseFilter *pSource);
PlaybackState m_state;
HWND m_hwnd; // Video window. This window also receives graph events.
IGraphBuilder *m_pGraph;
IMediaControl *m_pControl;
IMediaEventEx *m_pEvent;
CVideoRenderer *m_pVideo;
};
相关主题