1. New Project with the type of Qt Console Application
2. Add the following lines to the end of project file
LIBS += -L"C:/Program Files/Microsoft SDKs/Windows/v7.1/Samples/multimedia/directshow/baseclasses/Debug/" \
-lstrmbasd \
-lodbc32 \
-lodbccp32 \
-lkernel32 \
-luser32 \
-lgdi32 \
-lwinspool \
-lcomdlg32 \
-ladvapi32 \
-lshell32 \
-lole32 \
-loleaut32 \
-luuid \
-lodbc32 \
-lodbccp32
3. Run qmake
4. Edit the main.cpp
#include <dshow.h>
#include <iostream>
#include <Objbase.h>
#include <Winuser.h>
#include <QString>
#include <QtWidgets/QFileDialog>
#include <string>
using namespace std;
BOOL OpenFile1(TCHAR (&szFile)[MAX_PATH])
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = nullptr;
ofn.lpstrFilter = L"JPEG File(*.jpg)\0*.jpg\0"
L"Bitmap File(*.bmp)\0*.bmp\0"
L"AVI File(*.avi)\0\*.avi\0"
L"WMV File(*.wmv)\0*.wmv\0"
L"WMA File(*.wma)\0\*.wma\0"
L"MP3 File(*.mp3)\0\*.mp3\0"
L"MP4 File(*.mp4)\0\*.mp4\0"
L"All Files\0*.*\0\0";
ofn.lpstrInitialDir = L"G:\\Study Video\\Advanced Windows Store App Development with HTML5 Jump Start";
szFile[0] = TEXT('\0');
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrTitle = L"Open a media file";
ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST;
return GetOpenFileName(&ofn);
}
int main(int argc, char *argv[])
{
IGraphBuilder *pGraph;
IMediaControl *pMediaControl;
TCHAR szFile[MAX_PATH] = {0};
CoInitialize (NULL); // Initialize COM
//Create an instance of the Filter Graph Manager and obtain a pointer to the GraphBuilder
CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **) &pGraph);
//obtain a pointer to the MediaControl
pGraph->QueryInterface (IID_IMediaControl, (void **) &pMediaControl);
if(OpenFile1(szFile)){
//Build the graph based on the file format type
pMediaControl->RenderFile (szFile);
//Run the graph
pMediaControl->Run ();
}
//block
MessageBox (NULL, L"Click to terminate", L"DirectShow", MB_OK);
//Release
pMediaControl->Release ();
pGraph->Release ();
CoUninitialize ();
}
5. Build and urn