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
  • 566
  • 9
  • 25
  • 1
    tip: "I cant find anything" is hardly every true. It doesnt really make others want to help you more but rather suggests that you didnt search enough, just saying. If found eg this: https://stackoverflow.com/questions/22253074/how-to-play-or-open-mp3-or-wav-sound-file-in-c-program – 463035818_is_not_an_ai Nov 18 '19 at 21:07
  • what you linked is not related to what i'm looking to do so... and by the way i've been googling for about 7 hours now thank you – user3813360 Nov 18 '19 at 21:15
  • how is it not related? The question is about playing mp3 and the answer discusses `mciSendString` in details – 463035818_is_not_an_ai Nov 18 '19 at 21:16
  • no it's just playing a file, i can already do that, i want to play a file that is a RESOURCE in the project – user3813360 Nov 18 '19 at 21:17
  • 1
    thats not obvious from your question. Actually I dont know what you mean with "add as a resource". Is this some Visual Studio thingy? – 463035818_is_not_an_ai Nov 18 '19 at 21:19
  • i mean that i want just an executable file that has the sound file in it – user3813360 Nov 18 '19 at 21:25

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
  • 392
  • 1
  • 4
  • 21