Click here to Skip to main content
6,821,293 members and growing! (18,488 online)
Email Password   helpLost your password?
Multimedia » Audio and Video » Audio     Intermediate

Simple Media Player

By verma-rahul

A simple media player.
VC7.1, Windows, MFC, DirectX, VS.NET2003, Dev
Posted:14 Feb 2005
Views:77,636
Bookmarked:67 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
16 votes for this article.
Popularity: 3.10 Rating: 2.58 out of 5
7 votes, 43.8%
1
2 votes, 12.5%
2

3
2 votes, 12.5%
4
5 votes, 31.3%
5

Sample Image

Introduction

This program plays some audio/video (.avi, MPEG, MP3..) files. It uses DirectX 9.0 to play media files.

Software Requirements

Visual Studio .NET 2003, DirectX SDK 9.0.

Add the following libraries to the project:

Project->Properties->Linker->Input->Additional dependences
  • \\DXSDK\lib\strmiids.lib
  • \\DXSDK\Samples\C++\DirectShow\BaseClasses\Debug\strmbasd.lib

Instructions

Open a file by clicking Open button. Or open the playlist by pressing PlayList button. To add a file, click Add menu and Add File. You can select multiple files. Choose a file from playlist and click Play button on main window.

Classes

  • CWinPlayerDlg

    Class for main dialog.

  • CVideoWndDlg

    Dialog to display video.

  • CSeekSlider

    Class for the slider control.

  • CPlayList

    Class for list box to display the files to be played.

Playing media files

To render (output) a file, we need to instantiate various DirectX COM objects:

m_objHRsult=m_objGraphBuilder->QueryInterface (IID_IMediaControl, 
                                     (void**)&m_objMediaControl);
m_objHRsult=m_objGraphBuilder->QueryInterface (IID_IMediaEventEx, 
                                     (void**)&m_objMediaEvent);
m_objHRsult=m_objGraphBuilder->QueryInterface (IID_IVideoWindow, 
                                     (void**)&m_objVideownd);
m_objHRsult=m_objGraphBuilder->QueryInterface (IID_IMediaSeeking, 
                                     (void**)&m_objMediaSeeking);
m_objHRsult=m_objGraphBuilder->QueryInterface (IID_IMediaPosition, 
                                     (void**)&m_objMediaPos);
m_objHRsult= m_objGraphBuilder->QueryInterface(__uuidof(IVideoFrameStep), 
                                     (PVOID *)&m_objVideoFrame);

Give the reference to the owner window in which the file is displayed.

m_objVideownd->put_Owner((OAHWND) m_objVideoDlg.GetSafeHwnd());

To run the file:

m_objHRsult=m_objMediaControl->Run();

mfn_PauseClip()

To pause or play the clip, we check whether it is playing. If it is then:

m_objMediaControl->Pause()

pauses the Media control.

mfn_StepFrameFwd()

To move a clip forward to a certain number of frames, we do:

l_hResult=m_objVideoFrame->Step(15,NULL);

This moves 15 frames.

mfn_Close()

To close file:

l_hResult=m_objMediaControl->Stop();

Then to release all objects:

SAFE_RELEASE(m_objMediaEvent);
SAFE_RELEASE(m_objMediaPos);
SAFE_RELEASE(m_objMediaControl);
SAFE_RELEASE(m_objVideownd);
SAFE_RELEASE(m_objGraphBuilder);

Changing the position of slider:

Get current position:

DWORD dwPosition  = m_objSeekBar.GetPos();

Pause while scrolling:

m_objMediaControl->Pause();

Set new position:

REFERENCE_TIME newTime = (l_time/100) * dwPosition;
m_objMediaSeeking->SetPositions(&newTime, 
  AM_SEEKING_AbsolutePositioning, NULL, 
  AM_SEEKING_NoPositioning);

OnTimer()

Changes the position of slider control per second:

if (SUCCEEDED(m_objMediaSeeking->GetCurrentPosition(&timeNow)))
{
    l_PlayTime.Format("%d",timeNow/10000000);
    //ltoa((timeNow / 1000),l_PlayTime,10);

    m_objTimePlay.SetWindowText(l_PlayTime);
    long sliderTick = (long)((timeNow * 100) / l_time);
    m_objSeekBar.SetPos(sliderTick);
}

Acknowledgment

Code help is taken from DirectX SDK documentation. Guidance and support of Atin in this project is appreciable. Any suggestions and improvement in code are welcome. Further enhancement will be shortly available.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

verma-rahul


Member
Working at a programmer in Jaipur(India) for TRYST Tec. Pvt. Ltd. on VC++ .I did my B.E (Computer Sc.).Now I am working on ASP.net.
Occupation: Web Developer
Location: India India

Other popular Audio and Video articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 10 of 10 (Total in Forum: 10) (Refresh)FirstPrevNext
GeneralMy vote of 1 Pinmemberashar_0220:07 15 Dec '08  
GeneralQue Pinmemberharshal71880:38 29 Sep '08  
GeneralWindow Media Player APi for Win2000 Machine Pinmemberpreeti sharma4:56 18 Sep '08  
Generalcant change the play windows size Pinmembergooglelsg18:02 17 Sep '08  
Generalthe project don't compile Pinmemberalphavn4:12 19 Nov '06  
GeneralRe: the project don't compile PinmemberAbhishek Dutta6:33 11 Mar '07  
GeneralHow to display a picture Pinmemberyanamandras22:43 20 Oct '06  
Generalsearch code for visual c++ 6.0 enterprise edition Pinmemberfanomezana22:31 11 May '06  
QuestionHow to play DAT video files? Pinmemberreach2dpg6:28 2 Apr '06  
Generalvideo not showing Pinmembergrv57517:02 10 Jul '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

PermaLink | Privacy | Terms of Use
Last Updated: 14 Feb 2005
Editor: Smitha Vijayan
Copyright 2005 by verma-rahul
Everything else Copyright © CodeProject, 1999-2010
Web22 | Advertise on the Code Project