Click here to Skip to main content
14,774,184 members
Articles » Multimedia » Audio and Video » Audio
Article
Posted 13 Jun 2001

Stats

596.5K views
10.5K downloads
128 bookmarked

A very simple MP3 Player

Rate me:
Please Sign up or sign in to vote.
4.62/5 (54 votes)
13 Jun 2001
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

Share

About the Author

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

Comments and Discussions

 
QuestionDownload not working Pin
SouL Prisoner16-May-14 20:31
MemberSouL Prisoner16-May-14 20:31 
QuestionDownload Problem Pin
Abdul Rahman Kayali30-Nov-13 1:30
MemberAbdul Rahman Kayali30-Nov-13 1:30 
Questionerror on "MCIWndCreate" Pin
Mahdi Nejadsahebi30-Jun-12 2:17
MemberMahdi Nejadsahebi30-Jun-12 2:17 
GeneralMy vote of 4 Pin
markfilan8-Jan-11 6:38
Membermarkfilan8-Jan-11 6:38 
GeneralMy vote of 2 Pin
KarstenK26-Aug-10 23:29
mveKarstenK26-Aug-10 23:29 
GeneralSplitting a video file Pin
Vedavyasaachar19-Aug-09 1:19
MemberVedavyasaachar19-Aug-09 1:19 
Generaldownloading code Pin
mohammadarshad279-Apr-08 20:11
Membermohammadarshad279-Apr-08 20:11 
GeneralPlaying the file through buffer Pin
nitin_pro31-Oct-07 0:21
Membernitin_pro31-Oct-07 0:21 
QuestionPlaying the MP3 file through buffer Pin
nitin_pro22-Oct-07 2:39
Membernitin_pro22-Oct-07 2:39 
Generalit is just cool [modified] Pin
sooshia27-Jul-07 6:40
Membersooshia27-Jul-07 6:40 
GeneralThis cool! Pin
earth_cg8-Mar-07 7:54
Memberearth_cg8-Mar-07 7:54 
QuestionCan not play AVI Pin
prosens9-Oct-06 21:59
Memberprosens9-Oct-06 21:59 
GeneralMCI Error Pin
naraimha4-Oct-06 3:58
Membernaraimha4-Oct-06 3:58 
QuestionCan this program play WAV? Pin
Aki Wang3-Aug-06 0:55
MemberAki Wang3-Aug-06 0:55 
AnswerRe: Can this program play WAV? Pin
Aki Wang3-Aug-06 1:29
MemberAki Wang3-Aug-06 1:29 
GeneralAL Pin
vnsr8-Jun-06 5:00
Membervnsr8-Jun-06 5:00 
QuestionProblems Pin
nepobunceno18-Apr-06 14:42
Membernepobunceno18-Apr-06 14:42 
I have tried this program, and it seems simple enough. But there is one little problem, and I am not sure what the error could be. When I open the file, nothing appears to be happening. I have tried the program with other computers that don't have the codecs, and a white with red screen appears letting me know that I don't have the necessary codecs. So I'm not sure what the problem could be.

Thanks for your help
Questionhow to play the mp3 song in the required output device, is there any function to specify the output device id for mp3 Pin
Cpp guy22-Jun-05 2:05
MemberCpp guy22-Jun-05 2:05 
GeneralResolving Building Errors Pin
RobertOls19746-May-05 7:15
MemberRobertOls19746-May-05 7:15 
GeneralRe: Resolving Building Errors Pin
Anonymous30-Jun-05 5:36
MemberAnonymous30-Jun-05 5:36 
GeneralImplementing the progressbar Pin
Member 185549415-Apr-05 3:57
MemberMember 185549415-Apr-05 3:57 
GeneralAdding a volume button Pin
Member 16182599-Jan-05 16:05
MemberMember 16182599-Jan-05 16:05 
GeneralRe: Adding a volume button Pin
Anonymous30-Jun-05 5:19
MemberAnonymous30-Jun-05 5:19 
GeneralHide Slider Control Pin
Member 2431992-Dec-04 21:56
MemberMember 2431992-Dec-04 21:56 
GeneralRe: Hide Slider Control Pin
silufear15-Jun-07 16:51
Membersilufear15-Jun-07 16:51 

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.