Here's an example on how to play an mp3 in console.
The only thing you need is the directX SDK from microsoft.
with g_pMediaControl, you can control the mp3 (stop, pause, resume, etc.)
Just copy past the code in a console workspace and it should work.
Code:
#include <stdio.h>
#include <conio.h>
#include <dshow.h>
#pragma comment(lib, "amstrmid.lib")
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
IMediaControl *g_pMediaControl;
IMediaSeeking *g_pMediaSeeking;
IGraphBuilder *g_pGraphBuilder;
IBaseFilter *pSource;
bool PlayMP3(char filename[255])
{
LONGLONG llPos = 0;
IPin *pPin;
WCHAR wFilename[MAX_PATH];
#ifndef UNICODE
MultiByteToWideChar(CP_ACP,0,filename,-1,wFilename,MAX_PATH);
#else
lstrcpy(wFilename,filename);
#endif
::CoInitialize(NULL);
CoCreateInstance(CLSID_FilterGraph, NULL,CLSCTX_INPROC, IID_IGraphBuilder, (void **)&g_pGraphBuilder);
g_pGraphBuilder->QueryInterface(IID_IMediaControl,(void **)&g_pMediaControl);
g_pGraphBuilder->AddSourceFilter(wFilename, wFilename, &pSource);
pSource->FindPin(L"Output", &pPin);
g_pGraphBuilder->Render(pPin);
pPin->Release();
g_pGraphBuilder->QueryInterface(IID_IMediaSeeking, (void **)&g_pMediaSeeking);
g_pMediaSeeking->SetPositions(&llPos, AM_SEEKING_AbsolutePositioning, &llPos, AM_SEEKING_NoPositioning);
g_pMediaControl->Run();
return true;
}
int CleanUp()
{
SAFE_RELEASE(pSource);
SAFE_RELEASE(g_pMediaControl);
SAFE_RELEASE(g_pGraphBuilder);
SAFE_RELEASE(g_pMediaSeeking);
return 0;
}
int main()
{
int key;
for(;; )
{
system("cls"); //yeah yeah, I know, but this is only an example ;)
printf("1 :Play\n");
printf("2 :Quit\n");
key=getch();
switch(key)
{
case '1':
PlayMP3("my.mp3"); //!! enter the the correct path for your mp3
break;
case '2':
CleanUp();
return 0;
}
}
}