mci with C++

Started by
4 comments, last by mc30900 17 years, 9 months ago
hello all i got a problem. i learned from a tutorial and at the end i download the tutorial files. the tutorial is about playing mp3 with MCI. the problem is... i have no idea how to enter the name of the music file. i'll show u the code... there are 2 files the header and the main file. main file:

/////////////////////////////////////////////////////////
// Author:		Rob Zimmerman
// Description:	This simple console-based example shows
//	the steps needed to play an MP3 file using the
//	CMP3_MCI class.
/////////////////////////////////////////////////////////
#include <conio.h>
#include "CMP3_MCI.h"

int main(char* argv[])
{

	CMP3_MCI	MyMP3;
	char		cUserSelection = 0;

	MyMP3.Load(argv[1]);
	
	while(cUserSelection != '4')
	{
		system("cls");
		printf("Console MP3 Player\n");
		printf("1) Play\n");
		printf("2) Stop\n");
		printf("3) Pause\n");
		printf("4) Exit\n");
		printf("Enter Your Selection: ");
		cUserSelection = getch();

		switch(cUserSelection)
		{
		case '1':
			MyMP3.Play();
			break;
		case '2':
			MyMP3.Stop();
			break;
		case '3':
			MyMP3.Pause();
			break;
		}
	}

	return 0;
}






and the header file

/////////////////////////////////////////////////////////
// Author:		Rob Zimmerman
// Description:	This header file implements a class that
//	will manage a single MP3 file. Simply load the file,
//	the start playing it!
//	
//	Usage: Feel free to modify this file however you like. 
//		Drop me a line at rzimmerm@23rdhour.com if you 
//		use this in any way just so I can see what it's 
//		being used for. No charge of course ;)
/////////////////////////////////////////////////////////

#ifndef _MP3_USING_MCI
#define _MP3_USING_MCI

#include <string>
#include <windows.h>
#include <mmsystem.h>
class CMP3_MCI
{
public:
	CMP3_MCI(){m_bPaused = false;}
	~CMP3_MCI(){Unload();}

	inline void Load(char *szFileName)
	{
		m_szFileName = szFileName;
		Load();
	}

	inline void Load(std::string szFileName)
	{
		m_szFileName = szFileName;
		Load();
	}

	inline void Play()
	{
		std::string szCommand = "play " + GetFileName() + " from 0";
		mciSendString(szCommand.c_str(), NULL, 0, 0);
	}

	inline void Stop()
	{
		std::string szCommand = "stop " + GetFileName();
		mciSendString(szCommand.c_str(), NULL, 0, 0);
	}

	inline void Pause()
	{
		std::string szCommand;
		if(IsPaused())
		{
			szCommand = "resume " + GetFileName();
			mciSendString(szCommand.c_str(), NULL, 0, 0);
			SetPaused(false);
		}
		else
		{
			szCommand = "pause " + GetFileName();
			mciSendString(szCommand.c_str(), NULL, 0, 0);		
			SetPaused(true);
		}
	}

	inline void Unload()
	{
		std::string szCommand = "close" + GetFileName();
		Stop();
		mciSendString(szCommand.c_str(), NULL, 0, 0);
	}

	//Accessor's for private members.
	inline std::string GetFileName()
	{return m_szFileName;}

	inline bool IsPaused()
	{return m_bPaused;}

	inline void SetPaused(bool bPaused)
	{m_bPaused = bPaused;}
private:
	inline void Load()
	{
		std::string szCommand = "open \"" + GetFileName() + "\" type mpegvideo alias " + GetFileName();		
		mciSendString(szCommand.c_str(), NULL, 0, 0);
	}

	std::string m_szFileName;
	bool m_bPaused;
};
#endif




where can i enter the name of file?? i saw main take it as parameters but how i enter it? thanks in advance [Edited by - mc30900 on July 2, 2006 3:48:56 PM]
Advertisement
When you run the program, enter it on the command line (E.g. "blah.exe myfile.mp3"). Alternatively, there should be an option in your poeject settings to let you specify command line parameters to pass to the program (But I can't rmember where it is offhand)
well now i get a strange error when i try to compile it:
aaa.obj : error LNK2019: unresolved external symbol __imp__mciSendStringA@16 referenced in function "public: void __thiscall CMP3_MCI::Play(void)" (?Play@CMP3_MCI@@QAEXXZ)C:\Documents and Settings\&#1497;&#1492;&#1493;&#1504;&#1514;&#1503;\&#1513;&#1493;&#1500;&#1495;&#1503; &#1492;&#1506;&#1489;&#1493;&#1491;&#1492;\&#1514;&#1497;&#1511;&#1497;&#1492; &#1495;&#1491;&#1513;&#1492; (10)\blalba\Debug\blalba.exe : fatal error LNK1120: 1 unresolved externalsBuild log was saved at "file://c:\Documents and Settings\&#1497;&#1492;&#1493;&#1504;&#1514;&#1503;\&#1513;&#1493;&#1500;&#1495;&#1503; &#1492;&#1506;&#1489;&#1493;&#1491;&#1492;\&#1514;&#1497;&#1511;&#1497;&#1492; &#1495;&#1491;&#1513;&#1492; (10)\blalba\blalba\Debug\BuildLog.htm"
mciSendString
Quote:
Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Mmsystem.h; include Windows.h.
Library: Use Winmm.lib.
You need to link to Winmm.lib.
You need to link "Winmm.lib" -> "#pragma comment(lib, "Winmm.lib")".
Edit: 22 seconds late :)
there are no compiling problems now... but.. when i start the ExE file with the mp3 file ... it writes there is a problem and the program has to be shutted down.
anyone has any idea why this is happening???
or mybe a better tutorial for play mp3 with mic in c++
or a working code of that... anything?

thanks in advance

This topic is closed to new replies.

Advertisement