DirectShow 播放视频

来源:互联网 发布:vb.net通过opc西门子 编辑:程序博客网 时间:2024/05/17 22:45
 
  1. CComPtr<IGraphBuilder> m_pPlaybackGraph;
  2. // Create a graph to play the requested file
  3. hr = m_pPlaybackGraph.CoCreateInstance(CLSID_FilterGraph);
  4. ASSERT(m_pPlaybackGraph);
  5. // Render the media file
  6. hr = m_pPlaybackGraph->RenderFile(Filename,NULL);
  7. ASSERT(FAILED(hr));
  8. // Set video window to be a child window of the screen and
  9. // position it properly.
  10. CComQIPtr< IVideoWindow, &IID_IVideoWindow > pVW(m_pPlaybackGraph);
  11. //hWnd is window handle.
  12. hr = pVW->put_Owner((OAHWND)hWnd);
  13. ASSERT(FAILED(hr));
  14. // If the selected file has no video component, fail gracefully
  15. // and still play the audio portion
  16. if (SUCCEEDED(hr))
  17. {
  18.    // The video window must have the WS_CHILD style
  19.    hr = pVW->put_WindowStyle(WS_CHILD);
  20.    // Read coordinates of video container window
  21.    RECT rc;
  22.    GetWindowRect(hWnd,&rc);
  23.    long width =  rc.right - rc.left;
  24.    long height = rc.bottom - rc.top;
  25.    // Ignore the video's original size and stretch to fit bounding rectangle
  26.    hr = pVW->SetWindowPosition(rc.left, rc.top, width, height);
  27.    ASSERT(FAILED(hr));
  28. }
  1. // Start running the graph 
  2. CComQIPtr< IMediaControl, &IID_IMediaControl > m_pPlaybackControl(m_pPlaybackGraph);
  3. hr = m_pPlaybackControl->Run();
  4. ASSERT(FAILED(hr));
  1. // If there is no current graph, nothing needs to be done
  2. if (!m_pPlaybackGraph)
  3.     return;
  4. // Get media control and media seeking interfaces
  5. CComQIPtr< IMediaControl, &IID_IMediaControl > pMediaControl(m_pPlaybackGraph);
  6. CComQIPtr< IMediaSeeking, &IID_IMediaSeeking > pMediaSeeking(m_pPlaybackGraph);
  7. // Stop the graph
  8. hr = pMediaControl->Stop();
  9. if(FAILED(hr))
  10. {
  11.     AfxMessageBox(TEXT("Could not stop graph"));
  12.     return;
  13. }
  14. // Reset to first frame of movie (if the clip supports seeking)
  15. LONGLONG pos=0;
  16. hr = pMediaSeeking->SetPositions(&pos, AM_SEEKING_AbsolutePositioning ,
  17.                                  NULL, AM_SEEKING_NoPositioning);
  18. // Display the first frame of the movie.
  19. hr = pMediaControl->Pause();
  20. if(FAILED(hr))
  21. {
  22.     AfxMessageBox(TEXT("Could not pause graph"));
  23.     return;
  24. }

 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 电脑打开央视影音死机怎么办 先锋影音二级网页打不开怎么办 手机qq音乐登录失效怎么办 酷狗账号忘记了怎么办 手机qq音乐听不了歌怎么办 第一试用网密码忘了怎么办 玩h1z1画面卡顿怎么办 uu跑腿抢不到单怎么办 比特币加密忘了怎么办 路虎发现cd卡死怎么办 苹果手机帐号被锁定怎么办 苹果手机帐号锁定了怎么办 微博帐号被锁定怎么办 微博显示帐号被锁定怎么办 uc屏蔽了一个网站怎么办 uu跑腿送货遇到不方便收货怎么办 雷神加速器忘记暂停怎么办 obs直播开摄像头吃鸡掉帧怎么办 陌陌收到的礼物怎么办 吃了油腻的东西恶心怎么办 主播工资不发怎么办 主播工资被欠怎么办 直播平台不发工资坑主播怎么办 主播公司不发工资怎么办 梦幻月卡用完了怎么办 网易星球实名认证通过不了怎么办 认证过荔枝主播怎么办 苹果手机相机不对焦怎么办 苹果手机摄像头不能对焦了怎么办 闪电邮里面邮件太多怎么办 苹果手机和助理打不开怎么办 苹果我的世界打不开怎么办 ps试用7天到期了怎么办 皮肤锁不住水份怎么办 硫酸弄到皮肤上怎么办 直播时图像反看怎么办 快手直播权限被收回怎么办 快手直播权限被收回了怎么办 腾讯手游助手玩游戏卡怎么办 电脑直播视频打不开了怎么办 平板进水开不了机怎么办