DirectShow 播放视频

 
  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. }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白錵錵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值