What is DirectShow?

DirectShow (sometimes abbreviated as DS or DShow), codename Quartz, is a multimedia frameworl and API produced by Microsoft for software developers to perform various operations with media files or streams. It is the replacement for Microsoft’s earlier Video for Windows technology.Based on the Microsoft Windows Component Object Model (COM) framework, DirectShow provides a common interface for media across many,programming languages, and is an extensible, filter-based framework that can render or record media files on demand at the request of the user or developer. The DirectShow development tools and documentation were originally distributed as part of the DirectX SDK. Currently, they are distributed as part of the Windows SDK(formerly known as the Platform SDK).

BUILDING A MEDIA PLAYER WITH DIRECTSHOW

STEP1:

Initialize the COM library on the current thread and identifies the concurrency model as single-thread apartment (STA).

If failed(CoInitialize(NIL)) then Exit;

STEP2:

Initialize GraphBuilder,filters(codecs).

dsGraphBuilder   : IGraphBuilder    = NIL; // Used to open the file and render the filters

dsMediaControl   : IMediaControl    = NIL; // Play, Stop, Pause.

dsMediaSeeking   : IMediaSeeking    = NIL; // Set position.

dsBasicVideo     : IBasicVideo2      = NIL; // Video source size

dsBasicAudio     : IBASICAUDIO      = NIL;

dsVideoWindow    : IVideoWindow     = NIL; // Window positioning

dsMediaEventEx   : IMediaEventEx    = NIL; // Event handling

// Create DirectShow Graph

if failed(CoCreateInstance(CLSID_FilterGraph,NIL, CLSCTX_INPROC,IID_IGraphBuilder,dsGraphBuilder)) then exit;

// Get the IMediaControl Interface

if failed(dsGraphBuilder.QueryInterface(IID_IMediaControl,dsMediaControl)) then exit;

// Get the IMediaSeeking Interface

if failed(dsGraphBuilder.QueryInterface(IID_IMediaSeeking,dsMediaSeeking)) then exit;

// Get the IBasicAudio Interface

if failed(dsGraphBuilder.QueryInterface(IID_IBasicAudio,dsBasicAudio)) then exit;

// Get the IBasicWindow Interface

if failed(dsGraphBuilder.QueryInterface(IID_IBasicVideo,dsBasicVideo)) then exit;

// Get the IVideoWindow Interface

if failed(dsGraphBuilder.QueryInterface(IID_IVideoWindow,dsVideoWindow)) then exit;

// Get the IMediaEventEx Interface

if failed(dsGraphBuilder.QueryInterface(IID_IMediaEventEx,dsMediaEventEx)) then exit;

// Attach the IMediaEventEx interface to the main window

dsMediaEventEx.SetNotifyWindow(FormHWND, dsEventMessage, dsEventInstance);

// Enable IMediaEventEx notifications

dsMediaEventEx.SetNotifyFlags(dsEventsOn);

STEP3:

Now, if all succeded, we can render a file like this:

// Get filename in UNICODE
MultiByteToWideChar(CP_ACP,0,PChar(FileName),-1,@UnicodeFileName,MAX_PATH);

// Render the file filters
If dsGraphBuilder.RenderFile(@UnicodeFileName,nil) = S_OK then
Begin
SetVolume(Volume);
plState := stOpen;

If Assigned(dsMediaSeeking) then
Begin
dsMediaSeeking.GetDuration(MediaLength);
End;

// Set our form as the owner
dsVideoWindow.put_Owner(FormHWND);
// Set the video window messages (mouse/keyboard) to be routed to our form
dsVideoWindow.put_MessageDrain(FormHWND);
// Set the video window to be a child window of our form.
dsVideoWindow.put_WindowStyle(WS_CHILD or WS_CLIPSIBLINGS or WS_CLIPCHILDREN);

STEP4: PAUSE,PLAY,STOP

This is a very simple task. All you have to do is:

dsMediaControl.Run; //the media will play
dsMediaControl.Pause; //your media is paused
dsMediaControl.Stop;//your media is stopped

DirectShow Player Screenshot
Media Player Source Member download Media Player Example Free download