Click here to Skip to main content
15,867,330 members
Articles / Desktop Programming / MFC
Article

A very simple MP3 Player

Rate me:
Please Sign up or sign in to vote.
4.62/5 (54 votes)
13 Jun 2001 617.3K   10.7K   129   81
A simple MP3/AVI player using the VFW32 library

Introduction

I made a little sample program that enables you to play MP3 files without needing the AUDIOX library. I used the Windows Library VFW32.Lib

Just put the VFW32.lib in the Linker's space (Alt +F7) and add

#include "vfw.h"

to your principal file.

Once you've done this, you just need to use the MCI commands:

Steps :

  • Create a private variable HWND m_Video and BOOL Pause;

  • in the OnInitDialog set m_Video = NULL;

  • Put almost the Play button and add this source code on

Here are the functions I use in my dialog class to play/pause/resume and stop video playback.

m_Play is the 'Play' button control, m_Pause is the pause/resume button, Pause is a boolean value, and m_Video is a HWND.

void CAVIPlayerDlg::OnPlay() 
{
	m_Video = NULL;
	
	if(m_Video == NULL)
	{
		m_Video = MCIWndCreate(this->GetSafeHwnd(),
			AfxGetInstanceHandle(),
			WS_CHILD | WS_VISIBLE|MCIWNDF_NOMENU,m_Path);
		
	}
	else
	{
		MCIWndHome(m_Video);
	}
	
	MCIWndPlay(m_Video);
	Pause = FALSE;
	m_Play.EnableWindow(FALSE);
	
}

void CAVIPlayerDlg::OnPause() 
{
	if(Pause)
	{
		m_Pause.SetWindowText("Pause");
		MCIWndResume(m_Video);
		Pause = FALSE;
	}
	else
	{
		m_Pause.SetWindowText("Resume");
		MCIWndPause(m_Video);
		Pause = TRUE;
	}
}

void CAVIPlayerDlg::OnCancel() 
{
	if(m_Video !=NULL)
	{
		MCIWndDestroy(m_Video);
		OnOK();
	}
	CDialog::OnCancel();
}

void CAVIPlayerDlg::OnStop() 
{
	// TODO: Add your control notification handler code here
	MCIWndStop(m_Video);
	if(m_Video !=NULL)
	{
		MCIWndDestroy(m_Video);
	}
	m_Play.EnableWindow(TRUE);
}

I Suggest you to refer to the MCI Reference on the net at http://msdn.microsoft.com/library/psdk/multimed/mciwnd_3stv.htm

I also include an AVI player in this program. :-)

That's all for this !

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


Written By
United States United States
My name is BLaZe and I have 15 years old

Comments and Discussions

 
GeneralHide Slider Control Pin
Member 2431992-Dec-04 20:56
Member 2431992-Dec-04 20:56 
GeneralRe: Hide Slider Control Pin
silufear15-Jun-07 15:51
silufear15-Jun-07 15:51 
Generalm_Path Pin
loudawgg28-Apr-04 6:06
loudawgg28-Apr-04 6:06 
Questionhow can i modify this to play in linux Pin
maheshkk6-Apr-04 19:54
maheshkk6-Apr-04 19:54 
GeneralMMSYSTEM 296 ERROR while play mp3 file Pin
chuit5-Jan-04 10:28
chuit5-Jan-04 10:28 
QuestionCan this Mp3player run on a DSP chipset ? Pin
Jiangcr8117-Nov-03 15:49
Jiangcr8117-Nov-03 15:49 
GeneralGood but want more ;-) Pin
BoscoW14-Jun-03 5:48
BoscoW14-Jun-03 5:48 
GeneralRe: Good but want more ;-) Pin
electriac17-Nov-06 5:22
electriac17-Nov-06 5:22 
I have often been asked the question " Is there a simple way to play WAV and MP3 files from C#". I have in the past few days devoted myself to doing this and I have been able to create a simple C# form with a single button to play both MP3 and WAV files using only six lines of code.

The program utilizes the device control MP3P.OCX which must be registered with regsvr32.exe but I have created "setup.bat" to
do this.

There also must be the following .dll files present.

AxInterop.MP3PLib.dll
Interop.MP3PLib.dll

I have a mp3player.zip file containing the program which is named

MP3play.exx This must be renamed
mp3play.exe. I have done this to facilitate internet transmission.

I also have a zip file mp3play_source.zip with the source code.

I will send either of these to anyone interested.

electricfarm@gmail.com

electriac
Generalurgent help!!!!!!!! Pin
athira28-May-03 21:54
athira28-May-03 21:54 
Questionhow to detect end of song ? Pin
rmajda23-Apr-03 22:31
rmajda23-Apr-03 22:31 
AnswerRe: how to detect end of song ? Pin
oqnet19-Apr-05 14:41
oqnet19-Apr-05 14:41 
QuestionCan this mp3 player do real time decoding? Pin
fcfc13-Apr-03 22:56
fcfc13-Apr-03 22:56 
AnswerRe: Can this mp3 player do real time decoding? Pin
DJWALSH14-Apr-03 2:31
DJWALSH14-Apr-03 2:31 
GeneralRe: Can this mp3 player do real time decoding? Pin
shailesh4924-Jan-04 3:17
shailesh4924-Jan-04 3:17 
QuestionHow to size the AVI window Pin
tattalevieuxgrincheux9-Dec-02 17:53
tattalevieuxgrincheux9-Dec-02 17:53 
Generalexecute me Pin
NeverGrief27-Nov-02 4:57
NeverGrief27-Nov-02 4:57 
GeneralGood and Simple Pin
Anonymous31-Aug-02 6:45
Anonymous31-Aug-02 6:45 
GeneralRe: Good and Simple Pin
fanncy11-Sep-06 22:43
fanncy11-Sep-06 22:43 
QuestionHow to loop continously?? Pin
Ramees28-Aug-02 2:57
Ramees28-Aug-02 2:57 
AnswerRe: How to loop continously?? Pin
Anonymous20-Oct-02 17:20
Anonymous20-Oct-02 17:20 
GeneralRe: How to loop continously?? Pin
oqnet19-Apr-05 15:01
oqnet19-Apr-05 15:01 
GeneralGreat Program Pin
sk-i-za7-Aug-02 7:38
susssk-i-za7-Aug-02 7:38 
GeneralHolds on to previous file Pin
codermallu1-Aug-02 3:58
codermallu1-Aug-02 3:58 
GeneralRe: Holds on to previous file Pin
oqnet19-Apr-05 14:29
oqnet19-Apr-05 14:29 
GeneralCodecs required Pin
Armen Hakobyan22-Jul-02 16:40
professionalArmen Hakobyan22-Jul-02 16:40 

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.