Click here to Skip to main content
15,887,027 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 618.6K   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

 
GeneralRe: Not an MP3 player Pin
Christian Graus21-Jul-02 15:30
protectorChristian Graus21-Jul-02 15:30 
Generalagree. It is not the code that i expect. Pin
29-Jun-02 10:36
suss29-Jun-02 10:36 
GeneralGood job for 15 years old Pin
Brian V Shifrin14-Jun-01 5:30
Brian V Shifrin14-Jun-01 5:30 
GeneralRe: Good job for 15 years old Pin
BLaZe14-Jun-01 5:44
BLaZe14-Jun-01 5:44 
GeneralRe: Good job for 15 years old Pin
Carlos Antollini14-Jun-01 5:47
Carlos Antollini14-Jun-01 5:47 
GeneralRe: Good job for 15 years old Pin
Giles14-Jun-01 11:51
Giles14-Jun-01 11:51 
GeneralRe: Good job for 15 years old Pin
Carlos Antollini14-Jun-01 12:05
Carlos Antollini14-Jun-01 12:05 
GeneralRe: Good job for 15 years old Pin
Mike Stevenson18-Jun-01 10:32
Mike Stevenson18-Jun-01 10:32 
Yes... not long after I got my first Radio Shack TRS-80 (affectionately dubbed The Trash-80). It had a whopping 16k of ram and a blazing fast auto-control tape player. It could display 16 colors in low-res (read: 1" x 2" blocks on our TV).

I played Pyramid once and was fascinated! I wanted to figure out how they made it, so I made my grandparents send me to computer camp to learn BASIC and LOGO. LOL Those were the days. Wink | ;-)

-Mike Stevenson
CoderX@liquidmirror.com
Owner, Liquid Mirror Software (http://www.liquidmirror.com)
Owner, Shareware Junction (http://www.sharewarejunction.com)
Owner, Internet Shopping Spree (http://www.internetshoppingspree.com/)
GeneralRe: Good job for 15 years old Pin
19-Jun-01 9:29
suss19-Jun-01 9:29 
GeneralRe: What's Logo Pin
William E. Kempf21-Jun-01 9:10
William E. Kempf21-Jun-01 9:10 
GeneralRe: What's Logo Pin
Atlantys8-Feb-02 8:15
Atlantys8-Feb-02 8:15 
GeneralRe: Good job for 15 years old Pin
Swinefeaster11-Aug-01 20:00
Swinefeaster11-Aug-01 20:00 
GeneralRe: Good job for 15 years old Pin
Giles12-Aug-01 0:56
Giles12-Aug-01 0:56 
GeneralRe: Good job for 15 years old Pin
loyal ginger30-Aug-10 3:10
loyal ginger30-Aug-10 3:10 
GeneralRe: Good job for 15 years old Pin
loyal ginger30-Aug-10 7:58
loyal ginger30-Aug-10 7:58 
GeneralRe: Good job for 15 years old Pin
loyal ginger30-Aug-10 3:12
loyal ginger30-Aug-10 3:12 

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.