0

i'm using visual studio and i'd like to know how to add an mp3 file as a resource and then play it, i can't find anything on this!

for nom i've added the file to the resource folder but did i do it correctly i don't know my .rc file has a folder named "mp3" and in it is the file IDR_MP31 i've tried this:

PlaySound(L"mp3\\IDR_MP31", NULL, SND_RESOURCE | SND_ASYNC);

which doesn't seem to work unfortunately how would i reference my resource in my code? can i play it with mciSendString?

EDIT: i've got it playing .WAV files from memory but this isn"t ideal as it takes alot of memory

in resource.h:

#define IDR_WAVE1                       104

function

HINSTANCE h = ::GetModuleHandle(0);
HRSRC res = ::FindResource(h, MAKEINTRESOURCE(104), TEXT("WAVE"));
if (res == 0)
    return;

HGLOBAL global = ::LoadResource(h, res);
if (global == 0)
    return;

void* wav = ::LockResource(global);
if (wav == 0)
{
    UnlockResource(global);
    FreeResource(global);
    return;
}

PlaySound(LPCWSTR(wav), NULL, SND_MEMORY | SND_ASYNC | SND_NODEFAULT);


UnlockResource(global);
FreeResource(global);

if anyone knows how to play mp3 files that way, please tell me. thanks

user3813360
  • 576
  • 8
  • 22

1 Answers1

1

You should be able to play it with mciSendString: mciSendString("play mp3", NULL, 0, NULL);

This link also has some useful information too: https://www.codeproject.com/Articles/17279/Using-mciSendString-to-play-media-files

jcthomas113
  • 372
  • 1
  • 2
  • 20