您的位置:首页 > 其它

在中Visual Studio .NET 2003利用DirectShow播放媒体文件(二)

2004-04-12 12:28 549 查看
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />



3.设置工程属性

    项目→PlayWnd属性→配置属性→链接器→输入→附加依赖项,添加库文件Strmiids.lib 和Quartz.lib。

由于Dshow.h头文件是在任何DirectShow工程中都要用到的,因此我们stdafx.h加入如下行:

#include <Dshow.h>

 

4.设计对话框,如下:



 

IDC_STATIC
控件类型
Static Text
Caption
媒体文件名:
IDC_MEDIAFILE_EDIT
控件类型
Edit Control
IDC_BROWSE_BUTTON
控件类型
Button
Caption
浏览
IDC_VW_FRAME
控件类型
Picture Control
Type
Rectangle
IDC_PLAY_BUTTON
控件类型
Button
Caption
播放
IDC_PAUSE_BUTTON
控件类型
Button
Caption
暂停
IDCANCEL
控件类型
Button
Caption
关闭
5.COM的初始化和卸载,

修改PlayWnd.cpp添加初始化代码(加入的代码用黑体表示,下同)

 

BOOL CPlayWndApp::InitInstance()

{

    // 如果一个运行在 Windows XP 上的应用程序清单指定要

    // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,

    //则需要 InitCommonControls()。否则,将无法创建窗口。

    InitCommonControls();

 

    //初始化COM接口

    HRESULT hr = CoInitialize(NULL);

    if (FAILED(hr))

    {

       TRACE("ERROR - Could not initialize COM library./n");

       return FALSE;

    }

 

    CWinApp::InitInstance();

 

    AfxEnableControlContainer();

 

 
修改PlayWnd.cpp添加卸载COM代码,注意需要对虚函数ExitInstance进行重载

 

int CPlayFileApp::ExitInstance()

{

    // TODO: 在此添加专用代码和/或调用基类

    //关闭COM

    CoUninitialize();

 

    return CWinApp::ExitInstance();

}

   

 
6.定义媒体控制成员变量

    修改PlayWndDlg.h如下:

 

protected:

    HICON m_hIcon;

 

    // 生成的消息映射函数

    virtual BOOL OnInitDialog();

    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);

    afx_msg void OnPaint();

    afx_msg HCURSOR OnQueryDragIcon();

    DECLARE_MESSAGE_MAP()

 

//和媒体控制相关的成员变量

private:

IGraphBuilder *m_pGraph;    //IGraphBuilder 接口提供了生成Filter Graph相//关的方法

IMediaControl *m_pMediaControl; //IMediaControl 接口提供了控制流经Filter //Graph数据流的相关方法

IMediaEventEx *m_pEvent;    //IMediaEventEx 继承自IMediaEvent,提供了从//Filter Graph 管理器获取事件消息的方法

IMediaSeeking *m_pMediaSeeking; //IMediaSeeking 提供了控制流的播放位置和播放//速度的方法

 

    CString m_strMediaFile;         //当前播放的媒体文件的名称

    BOOL m_isPlaying;           //当前的播放状态

};

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息