Click here to Skip to main content
13,151,514 members (47,860 online)
Click here to Skip to main content
Add your own
alternative version


52 bookmarked
Posted 1 Feb 2003

Media Player

, 20 Sep 2003
Rate this:
Please Sign up or sign in to vote.
Its a media player which plays all media audio and video files.

Sample image

Sample image

<!-- Add the rest of your HTML here -->


Media Player

This is a simple media player which plays all audio and video formats .I am updating it becouse there were many of many complaints about it . Actually i had not time to do it , now found some ,so updating it . It uses Media Control Interface(MCI) Functions in the MFC .It is very simple , that is we only have to give the path and file name and other parameters to the function and the function will play that file .


First the file names are taken from the user using the file dialog .These file name are stored in an array of CString type Files[Index] ; Index is the the index of files .Multiple files can be selected at a time . Now to Create window of playing the file is created in the following  function

<PRE lang=mc++>void CMP3Dlg::CreateWindowplay(CString str) { if(m_Video!=NULL)    // m_video is handler of HWND type which is <PRE lang=mc++> //checked wether it has already some window data OnFileClose();  m_Path=str; MCIWndRegisterClass(); KillTimer(0); SetTimer(0,1000,NULL);   //  Set Timer m_Path=str; if(m_Video == NULL &&flag==0) { m_Video =MCIWndCreate(m_screen.GetSafeHwnd(),AfxGetInstanceHandle()<PRE lang=mc++>,MCIWNDF_NOOPEN|MCIWNDF_NOPLAYBAR |MCIWNDF_NOMENU,m_Path);   <PRE lang=mc++>// Create the Window for playing m_Path  is file name ::ShowWindow(m_Video,SW_MAXIMIZE); } m_SVolume.SetRange( 0, 1000, TRUE );  // Set Slider range m_SVolume.SetPos(500);   // Set volume Position initially m_mute.SetCheck(1);  // Set Checked the Volume check box ptr=FromHandle(m_Video);   // Get handler of Window created ptr->UpdateWindow(); MCIWndSetTimeFormat(m_Video ,"ms");   // Set time Format m_length=MCIWndGetLength(m_Video );   // Get Video Length TotalTime=m_length/1000; TotalTime=TotalTime/100; m_Seek.SetRange( 0, m_length, TRUE );   // Set Seek slider bar range m_Seek.SetPos(0); MCIWndPlay(m_Video);   // Play the File flag=1; UpdateData(FALSE); MCIWndSetVolume(m_Video, m_Volume);   // Set Volume to m_Volume e=0; // Check for previus created window }

So now Our window is created and file is played . Now there is a option for pause that is

void CMP3Dlg::Onpause() 
// TODO: Add your control notification handler code here



to stop 

To move to next file ,

OnFileClose() ;
if(Files[SongNo]!="" )
CreateWindowplay(Files[SongNo]);  // again Create the window 
OnPlayPrevius() ;   // check if Index is full play previous 
The is a Implemenation for CD ROM door open and close . this is done as ,
// mciSendString("set cdaudio door open",NULL,NULL,NULL);

To Increase the Speed of Play

int a;

Similarly there is a function to decrease the speed

For full screen option,  there is another dialog upon which the window is created . The dialog is maximized so full screen is got . It is done as

void CMP3Dlg::OnViewFullscreen() 
// TODO: Add your command handler code here
FullScreen=1;   // flag of full screen , Mode is Full screen
KillTimer(0);   // Kill timer
MCIWndDestroy(m_Video);  // destroy previous window 

// Now save the Context of Current file for full screen through FS object of 
//FullScreen Dialog
FS.SeekPos=SeekPos;   // Get seek position of previous window for new dialog 
 			//(Full screen)
FS.m_Volume=m_Volume;   // Get 
FS.DoModal();           // Create New dialog
SeekPos=FS.SeekPos;  // Return Back to Normal size and get New 
      			//Context from Full screen 
if(SeekPos==m_length )
if( repeat==1) 
OnPlayNext();    // Check whether the file has ended or seek is at end so 
                 //next file will also be played in the full //screen mode
Onfullscreen() ;


flag=1;   // Re-create Window for normal size play   
::ShowWindow(m_Video,SW_MAXIMIZE);  // Restore the all Conext , volume value 
					//, seek postion ,,etc
MCIWndSetTimeFormat(m_Video ,"ms");
Now In new dialog Create Window and play according to previous context,
We will do it in the ShowWindow Function which is called first time when the
 dialog is created .
void FScreen::OnShowWindow(BOOL bShow, UINT nStatus) 
CDialog::OnShowWindow(bShow, nStatus);
CWnd* desk=GetDesktopWindow();  // Get the Desktop window's pointer
RECT re;
::ShowWindow(this->GetSafeHwnd(),SW_MAXIMIZE);   // Maximize window
// Now Create window for playing the file 
::ShowWindow(m_Video,SW_MAXIMIZE);  // Now set the previous saved context 
MCIWndSetTimeFormat(m_Video ,"ms");
MCIWndSetVolume(m_Video, m_Volume);

We can add and remove  files to the Play list . There is another dialog for 
play list . 

To add files :

void playlist1::OnAdd() 
,"All Files(*.*)|*.*|MP3 Files (*.mp3)|*.mp3|AVI Files(*.avi)|*.avi|");
if(avi.DoModal() == IDOK)
currPos = avi.GetStartPosition();
while(currPos != NULL)              // Get file names while now end of 
m_Path = avi.GetNextPathName(currPos);
((CMP3Dlg *)GetParent())->Files[((CMP3Dlg*)GetParent())->m_Index]=m_Path;
m_control.AddString(m_Path);  // Add to List box

Similary we can remove file through function 
void playlist1::OnRemove() 
// TODO: Add your control notification handler code here
m_control.DeleteString( i );
for(int j=0;j<=((CMP3Dlg*)GetParent())->m_Index;j++)
for(int h=i;h<((CMP3Dlg*)GetParent())->m_Index;h++)


We can play a file  by double clicking on  File name


The Shape of Dialog is got through
CRect r;

So thats all from me .What  could be done more in it ? that could be

1. We does not know about the file in the program ,whether its audio or video ,if audio to dont go to full screen

2. The full screen mechanism is not efficient , also it needs menu in full screen on right click .

3. Implementation of VCD cutter

and much more !!!!!!!!!!!!!



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Tahir Naeem
No Biography provided

You may also be interested in...

Comments and Discussions

BugError while playing .wav file Pin
vijaykumar.soni22-Mar-13 0:07
membervijaykumar.soni22-Mar-13 0:07 
Questiondfd Pin
prabhatjain4-Oct-12 15:22
memberprabhatjain4-Oct-12 15:22 
AnswerRe: dfd Pin
Tahirn14-Jul-14 20:43
memberTahirn14-Jul-14 20:43 
Questiontoyou Pin
zhangxiangxixi6-Dec-11 1:57
memberzhangxiangxixi6-Dec-11 1:57 
Questionabout information about the references Pin
Member 81126534-Aug-11 0:40
memberMember 81126534-Aug-11 0:40 
Questionimplementation Pin
vinuvadakkemuriyil19-Jul-11 23:01
membervinuvadakkemuriyil19-Jul-11 23:01 
GeneralAnaglyph/3d player Pin
ankireddy112231-Oct-10 20:34
memberankireddy112231-Oct-10 20:34 
GeneralRunning the Project Pin
selonda19-Sep-10 22:44
memberselonda19-Sep-10 22:44 
Questionneed to build project Pin
satilo1-Aug-10 16:39
membersatilo1-Aug-10 16:39 
GeneralDev-C++ Pin
smely3-Dec-09 21:59
membersmely3-Dec-09 21:59 
GeneralRe: Dev-C++ Pin
Tahir Naeem13-Mar-10 9:12
memberTahir Naeem13-Mar-10 9:12 
GeneralNeed help on moving a line along with the audio slider position Pin
venki50218-Feb-09 7:08
membervenki50218-Feb-09 7:08 
Hi Tahir,
I have created player application using MCI funtions, now i have one slider control and one image on the top of the dialog.

I want to move a vertical line along the slider position, and across the images.
I am able to move the slider position, but not able to move the line with respect to slider position.

Can you please help me regarding this..?

Thanks in advance..
Questionhow to integrate new codec into this player? Pin
Santosh Chaurasia30-Jul-08 4:12
memberSantosh Chaurasia30-Jul-08 4:12 
AnswerRe: how to integrate new codec into this player? Pin
Tahir Naeem30-Jul-08 5:31
memberTahir Naeem30-Jul-08 5:31 
GeneralRe: how to integrate new codec into this player? Pin
Santosh Chaurasia30-Jul-08 5:45
memberSantosh Chaurasia30-Jul-08 5:45 
GeneralRe: how to integrate new codec into this player? Pin
Tahir Naeem2-Aug-08 9:33
memberTahir Naeem2-Aug-08 9:33 
GeneralBUG !!! Pin
anmytry25-Jan-08 2:19
memberanmytry25-Jan-08 2:19 
GeneralRe: BUG !!! Pin
Tahir Naeem14-Feb-08 2:38
memberTahir Naeem14-Feb-08 2:38 
Questionkeyboard accelerator? Pin
m2sawyer27-Feb-07 4:24
memberm2sawyer27-Feb-07 4:24 
AnswerRe: keyboard accelerator? Pin
Tahir Naeem28-Feb-07 7:55
memberTahir Naeem28-Feb-07 7:55 
GeneralMCI Error Pin
naraimha2-Oct-06 23:42
membernaraimha2-Oct-06 23:42 
GeneralRe: MCI Error Pin
Tahir Naeem3-Oct-06 1:22
memberTahir Naeem3-Oct-06 1:22 
GeneralRe: MCI Error Pin
naraimha3-Oct-06 2:47
membernaraimha3-Oct-06 2:47 
GeneralRe: MCI Error Pin
Tahir Naeem3-Oct-06 2:51
memberTahir Naeem3-Oct-06 2:51 
Generalcant play VOB files Pin
luniv04048-Nov-04 2:23
sussluniv04048-Nov-04 2:23 
GeneralRe: cant play VOB files Pin
Tahir Naeem8-Feb-05 0:34
sussTahir Naeem8-Feb-05 0:34 
GeneralError Pin
Zero_Master9-Feb-04 20:40
memberZero_Master9-Feb-04 20:40 
GeneralRe: Error Pin
lwinkenb24-Apr-04 11:24
memberlwinkenb24-Apr-04 11:24 
QuestionWindows Media Player example in win32? Pin
dobrin_s_ivanov@yahoo.com30-Oct-03 2:15
memberdobrin_s_ivanov@yahoo.com30-Oct-03 2:15 
AnswerRe: Windows Media Player example in win32? Pin
Anonymous1-Dec-03 23:44
sussAnonymous1-Dec-03 23:44 
GeneralError in resource Pin
FahadAsh22-Sep-03 19:09
memberFahadAsh22-Sep-03 19:09 
GeneralRe: Error in resource Pin
Tahir Naeem30-Sep-03 1:24
memberTahir Naeem30-Sep-03 1:24 
GeneralI wouldn't call this an article. Pin
lallous19-Jun-03 22:17
memberlallous19-Jun-03 22:17 
GeneralHelp regarding Skin and others Pin
AYSHA SAEED22-Feb-03 4:15
memberAYSHA SAEED22-Feb-03 4:15 
GeneralAakhir Bahrian Hi Ho Nan,Code Nahin Dia Pin
XclusiveGuy7-Feb-03 23:16
memberXclusiveGuy7-Feb-03 23:16 
GeneralWelcome to CodeProject!! Pin
WREY3-Feb-03 23:47
memberWREY3-Feb-03 23:47 
GeneralThis could be a really interesting article if... Pin
Jim Crafton3-Feb-03 5:45
memberJim Crafton3-Feb-03 5:45 
GeneralRe: This could be a really interesting article if... Pin
Tahir Naeem4-Feb-03 6:38
memberTahir Naeem4-Feb-03 6:38 
GeneralRe: This could be a really interesting article if... Pin
Jim Crafton3-Jul-03 3:50
memberJim Crafton3-Jul-03 3:50 
GeneralRe: This could be a really interesting article if... Pin
Tahir Naeem3-Jul-03 11:38
memberTahir Naeem3-Jul-03 11:38 
GeneralRe: This could be a really interesting article if... Pin
nn_10524-Oct-05 9:12
membernn_10524-Oct-05 9:12 
Questionwhere's the source? Pin
anonymousone2-Feb-03 20:56
sussanonymousone2-Feb-03 20:56 
AnswerRe: where's the source? Pin
Simon Brown3-Feb-03 1:42
memberSimon Brown3-Feb-03 1:42 
GeneralRe: where's the source? Pin
Tahir Naeem27-Jul-03 12:18
memberTahir Naeem27-Jul-03 12:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170924.2 | Last Updated 21 Sep 2003
Article Copyright 2003 by Tahir Naeem
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid