![]() |
Multimedia »
Audio and Video »
Audio
Intermediate
Simple Media PlayerBy verma-rahulA simple media player. |
VC7.1, Windows, MFC, DirectX, VS.NET2003, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

This program plays some audio/video (.avi, MPEG, MP3..) files. It uses DirectX 9.0 to play media files.
Visual Studio .NET 2003, DirectX SDK 9.0.
Add the following libraries to the project:
Project->Properties->Linker->Input->Additional dependences
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.
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.
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();
To pause or play the clip, we check whether it is playing. If it is then:
m_objMediaControl->Pause()
pauses the Media control.
To move a clip forward to a certain number of frames, we do:
l_hResult=m_objVideoFrame->Step(15,NULL);
This moves 15 frames.
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);
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);
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); }
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.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
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 |