Click here to Skip to main content
Click here to Skip to main content

A very simple MP3 Player

By , 13 Jun 2001
 
<!-- Download Links --> <!-- Main HTML starts here -->

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

About the Author

BLaZe

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionerror on "MCIWndCreate"memberMahdi Nejadsahebi30-Jun-12 1:17 
GeneralMy vote of 4membermarkfilan8-Jan-11 5:38 
GeneralMy vote of 2memberKarstenK26-Aug-10 22:29 
GeneralSplitting a video filememberVedavyasaachar19-Aug-09 0:19 
Generaldownloading codemembermohammadarshad279-Apr-08 19:11 
GeneralPlaying the file through buffermembernitin_pro30-Oct-07 23:21 
QuestionPlaying the MP3 file through buffermembernitin_pro22-Oct-07 1:39 
Generalit is just cool [modified]memberjacej27-Jul-07 5:40 
GeneralThis cool!memberearth_cg8-Mar-07 6:54 
QuestionCan not play AVImemberpsamir9-Oct-06 20:59 
GeneralMCI Errormembernaraimha4-Oct-06 2:58 
QuestionCan this program play WAV?memberAki Wang2-Aug-06 23:55 
AnswerRe: Can this program play WAV?memberAki Wang3-Aug-06 0:29 
GeneralALmembervnsr8-Jun-06 4:00 
QuestionProblemsmembernepobunceno18-Apr-06 13:42 
Questionhow to play the mp3 song in the required output device, is there any function to specify the output device id for mp3memberFarooq kotwal22-Jun-05 1:05 
GeneralResolving Building ErrorsmemberRobertOls19746-May-05 6:15 
GeneralRe: Resolving Building ErrorssussAnonymous30-Jun-05 4:36 
GeneralImplementing the progressbarmemberretgrr34t15-Apr-05 2:57 
GeneralAdding a volume buttonmemberSaraMalkaW9-Jan-05 15:05 
GeneralRe: Adding a volume buttonsussAnonymous30-Jun-05 4:19 
GeneralHide Slider Controlmemberjun___2-Dec-04 20:56 
GeneralRe: Hide Slider Controlmembersilufear15-Jun-07 15:51 
Generalm_Pathmemberloudawgg28-Apr-04 6:06 
Questionhow can i modify this to play in linuxmembermaheshkk6-Apr-04 19:54 
GeneralMMSYSTEM 296 ERROR while play mp3 filememberchuit5-Jan-04 10:28 
QuestionCan this Mp3player run on a DSP chipset ?memberJiangcr8117-Nov-03 15:49 
GeneralGood but want more ;-)memberBoscoW14-Jun-03 5:48 
GeneralRe: Good but want more ;-)memberelectriac17-Nov-06 5:22 
Generalurgent help!!!!!!!!susssantra28-May-03 21:54 
Questionhow to detect end of song ?memberrmajda23-Apr-03 22:31 
AnswerRe: how to detect end of song ?sussoqnet19-Apr-05 14:41 
QuestionCan this mp3 player do real time decoding?memberfcfc13-Apr-03 22:56 
AnswerRe: Can this mp3 player do real time decoding?memberDJWALSH14-Apr-03 2:31 
GeneralRe: Can this mp3 player do real time decoding?membershailesh4924-Jan-04 3:17 
QuestionHow to size the AVI windowmembertattalevieuxgrincheux9-Dec-02 17:53 
Generalexecute mememberNeverGrief27-Nov-02 4:57 
GeneralGood and SimplesussAnonymous31-Aug-02 6:45 
GeneralRe: Good and Simplememberfanncy11-Sep-06 22:43 
QuestionHow to loop continously??memberRamees28-Aug-02 2:57 
AnswerRe: How to loop continously??sussAnonymous20-Oct-02 17:20 
GeneralRe: How to loop continously??sussoqnet19-Apr-05 15:01 
GeneralGreat Programsusssk-i-za7-Aug-02 7:38 
GeneralHolds on to previous filemembercodermallu1-Aug-02 3:58 
GeneralRe: Holds on to previous filesussoqnet19-Apr-05 14:29 
GeneralCodecs requiredmemberArmen Hakobyan22-Jul-02 16:40 
Generalplay avi files in .net environmentmemberlinus lee20-May-02 22:16 
GeneralChanging soundcards.memberLargie2-Mar-02 0:51 
GeneralRe: Changing soundcards.memberBLaZiNiX2-Mar-02 6:04 
GeneralRe: Changing soundcards.memberLargie3-Mar-02 21:04 

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130619.1 | Last Updated 14 Jun 2001
Article Copyright 2001 by BLaZe
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid