Click here to Skip to main content
Email Password   helpLost your password?

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 :

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 !

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralSplitting a video file
Vedavyasaachar
1:19 19 Aug '09  
How can i split a video file and store it.?Please help me .
Generaldownloading code
mohammadarshad27
20:11 9 Apr '08  
if i had made a website ,which provides a download option.than what will be the coding for that option.
please can u tell me .
GeneralPlaying the file through buffer
nitin_pro
0:21 31 Oct '07  
Hello
I had downloaded your source code of MP3 Player it helps it but i have some problem actually i want to give the buffer as input instead of file.
I want to pass the buffer of a playing file.


QuestionPlaying the MP3 file through buffer
nitin_pro
2:39 22 Oct '07  
Hello
I had downloaded your source code of MP3 Player it helps it but i have some problem actually i want to give the buffer as input instead of file.
I want to pass the buffer of a playing file.
kindly look into the matter
Generalit is just cool [modified]
jacej
6:40 27 Jul '07  
i have been looking mp3 play method with mfc about an hour
and this solution is greeeeeeeeeat!

thank you.Big Grin
GeneralThis cool!
earth_cg
7:54 8 Mar '07  
This project so good. Smile Big Grin

chamrus manyean

GeneralCan not play AVI
psamir
21:59 9 Oct '06  
I am not able to play avi files with this player. I am getting an error saying:"There is no driver installed on your system". How to resolve this issue?
GeneralMCI Error
naraimha
3:58 4 Oct '06  
Hi,
When i am using this application in windows 2000 i am getting small error message --MCI Error, and same application when i am using windowsXP i am not getting any error.Confused
GeneralCan this program play WAV?
Aki Wang
0:55 3 Aug '06  

Hi,

Can this program play WAV?
If not, how can I modify it so that it can play both mp3 and wav?
Thank you very much!



GeneralRe: Can this program play WAV?
Aki Wang
1:29 3 Aug '06  


Aki Wang wrote:
Hi,

Can this program play WAV?
If not, how can I modify it so that it can play both mp3 and wav?
Thank you very much!

I have tried it.It can play WAV!
Thank you! Wink


GeneralAL
vnsr
5:00 8 Jun '06  
Dear Blaze
I 've used your code. It 's simple but greate enough to run properly. But there 's still one problem I cannot overcome. I'm writting a "Multi AVI Player" Application using MultiThreading technique. When I tried to run many AVI files on many dialogs at the same time, the problem appears. ONLY THE PLAYER ON THE FIRST THREAD SOUNDS AND THE OTHER ARE SILENT. I did try to fix it, but nothing changed. Please give me some advices for this. Thank you very much (^__^)
From HoChiMinh City, VietNam
vnsr

datdo
QuestionProblems
nepobunceno
14:42 18 Apr '06  
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
Generalhow to play the mp3 song in the required output device, is there any function to specify the output device id for mp3
Farooq kotwal
2:05 22 Jun '05  
Plz can any one tell how to play the mp3 song in the required device when there are more than one sound card present in the system. For wav songs when we play the song we can specify the device id in to which the wave song must be played. Is there any such mechanism for playing the mciwnd songs....

Farooq Kotwal
GeneralResolving Building Errors
RobertOls1974
7:15 6 May '05  
Hi there,

thanks for the good article. I receive building errors though:

Elsa error LNK2019: unresolved external symbol _MCIWndCreateA referenced in function "public: bool __thiscall CElsaDlg::startBildspel(void)" (?startBildspel@CElsaDlg@@QAE_NXZ)

Elsa error LNK2019: unresolved external symbol _MCIWndRegisterClass referenced in function "public: bool __thiscall CElsaDlg::startBildspel(void)" (?startBildspel@CElsaDlg@@QAE_NXZ)

Elsa fatal error LNK1120: 2 unresolved externals

Does anyone have a clue what I am doing wrong here?

Thanks,

Robert

GeneralRe: Resolving Building Errors
Anonymous
5:36 30 Jun '05  
Did you link with VFW32.Lib? What Visual Studio version are you using?
GeneralImplementing the progressbar
retgrr34t
3:57 15 Apr '05  
Hi,
I want the code for implementing the progress bar in the GUI and that should be related to the song played.Means it is just similar to the GUI of Winamp,there in leftside we can see the plots plotted according to the frequency of the song.

Thanks.
With Regards,
Lavanya

GeneralAdding a volume button
SaraMalkaW
16:05 9 Jan '05  
Hi! I downloaded the player and I am trying to add volume buttons in MFC. I added the buttons and functions with the class wizard in Visual C++, but my functions are not working. Here is my code:
void CAVIPlayerDlg::OnVolumeDown()
{
long vol;
vol = MCIWndGetVolume(m_Video);

vol-=250;
MCIWndSetVolume(m_Video,vol);

}

void CAVIPlayerDlg::OnVolumeUp()
{
long vol;
vol = MCIWndGetVolume(m_Video);

vol+=250;
MCIWndSetVolume(m_Video,vol);

}
It runs, but the call MCIWndGetVolume(m_Video) returns 0 each time, and the volume isn't affected. Any ideas?
GeneralRe: Adding a volume button
Anonymous
5:19 30 Jun '05  
Forget the GetVolume function, put a variable with the desired volume into your application and use that instead.
GeneralHide Slider Control
jun___
21:56 2 Dec '04  
How to hide the slider control that appear when play sound ???
GeneralRe: Hide Slider Control
silufear
16:51 15 Jun '07  
when create function, join following parameter:
MCIWNDF_NOPLAYBAR

more parameter you can find it on MSDN.
Generalm_Path
loudawgg
7:06 28 Apr '04  
I'm having trouble with the m_Path, says it is an undeclared identifier. I can't find anywhere in your program where you identify m_Path. It also says something about binary '=' problem with the m_Path.

xero
Generalhow can i modify this to play in linux
maheshkk
20:54 6 Apr '04  
i checked ur article. its great. i tryed some other options and i got them all. but i went to run this article in linux(red hat 9) and i failed i modify some of the library but that does not work. please help me regerding this
GeneralMMSYSTEM 296 ERROR while play mp3 file
chuit
11:28 5 Jan '04  
Hi,
First of all, I would like to say that this simple MP3 Player is good, but I have a problem to use it on some PC. I can compiled and
play the mp3 file well in my original Windows OS - 98.
However, when I try to move the exe file to another PC
with Windows 98 as well, the application cannot play any
mp3 file. It always pops up the MMSYSTEM error, as shown
below:
"MMSYSTEM296 The file cannot be played on the specified
MCI device. The file may be corrupt, or not in the
correct format."

I tried many ways, such as copy a good mp3 file to the PC,
change the mp3 registter key, run the mmsys296.exe, etc,but none of them work.

Any idea how to fix this problem?

chui
GeneralCan this Mp3player run on a DSP chipset ?
Jiangcr81
16:49 17 Nov '03  
Smile
Can this MP3Player run on a DSP chipset?
How to change it?
GeneralGood but want more ;-)
BoscoW
6:48 14 Jun '03  
Hi I'm making an Mp3 Player witch this code is also simple but it can a bit more you can download it at http://www.upgmp3player.de.vu (german website but you should find the download link Wink )
but now i want to make it better and i look into the msdn so now i know that i can make it more better with this method of playing mp3 So if someone can give me some links for other methods ...

THX THX THX


Last Updated 14 Jun 2001 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010