Hi
I am relatively new to c++ but have written a program that would benefit from a little background music. I need it to be mp3 format. I am using dev c++ on windows XP.
can anyone help?
Hi
I am relatively new to c++ but have written a program that would benefit from a little background music. I need it to be mp3 format. I am using dev c++ on windows XP.
can anyone help?
A compact, practical add-on: on Win32 (Windows XP) the in-process DirectShow filter graph is a reliable way to play MP3s and implement looping without launching an external player. It gives event callbacks, seeks, and basic volume control so background music can run continuously while the app stays responsive. As and hinted, there are both OS-level and third-party routes; DirectShow is the OS-level route that fits neatly into a C++ program.
// Minimal DirectShow loop example.
// Requires <dshow.h> and linking with Strmiids.lib
#include <windows.h>
#include <dshow.h>
int main()
{
IGraphBuilder *pGraph = NULL;
IMediaControl *pControl = NULL;
IMediaEvent *pEvent = NULL;
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr)) return -1;
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void**)&pGraph);
if (SUCCEEDED(hr)) {
hr = pGraph->RenderFile(L"C:\\path\\to\\bg.mp3", NULL);
if (SUCCEEDED(hr)) {
pGraph->QueryInterface(IID_IMediaControl, (void**)&pControl);
pGraph->QueryInterface(IID_IMediaEvent, (void**)&pEvent);
pControl->Run();
long evCode = 0;
while (SUCCEEDED(pEvent->WaitForCompletion(INFINITE, &evCode))) {
if (evCode == EC_COMPLETE) {
IMediaSeeking *pSeek = NULL;
if (SUCCEEDED(pGraph->QueryInterface(IID_IMediaSeeking, (void**)&pSeek))) {
LONGLONG pos = 0;
pSeek->SetPositions(&pos, AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning);
pSeek->Release();
pControl->Run(); // restart
} else break;
} else break;
}
}
}
if (pControl) pControl->Stop();
if (pEvent) pEvent->Release();
if (pControl) pControl->Release();
if (pGraph) pGraph->Release();
CoUninitialize();
return 0;
} Notes and troubleshooting:
Jump to Post— Duoas 1,025I've never used Dev-C++, but it should have a Windows MediaPlayer component that you can drop on your application, and use it to play the MP3.
You can also google "msdn media control interface" for the APIs you can use to manipulate media devices on Windows.
Good luck.
I've never used Dev-C++, but it should have a Windows MediaPlayer component that you can drop on your application, and use it to play the MP3.
You can also google "msdn media control interface" for the APIs you can use to manipulate media devices on Windows.
Good luck.
try using FMOD.
Will this play continuously? if not do you know how i can do that?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.