Hack Forums
[C] How to add and play mp3 from resources - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] How to add and play mp3 from resources (/showthread.php?tid=6025973)



How to add and play mp3 from resources - Ryze - Nov 18, 2019

C++
basically i'm trying to add an mp3 file as a resource in visual studio and then play it but somehow i can't find any examples online!
how is this possible??


EDIT: i've got it working on playing .WAV files but it takes alot of memory  😑

resource.h:
PHP Code

<?php 
#define IDR_WAVE1                       104 

function:
PHP Code

<?php 
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 has a better solution to play embedded mp3 files not using 3rd party libraries, let me know

EDIT2: i think what i'll do is download the sound file and play it, it's easier and makes my binary lighter