Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

How to add and play mp3 from resources

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


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by Account of the GodsAug 15, 2017 05:33 AM 6 299 Aug 15, 2017 05:33 AM
Last Post: Mohinder
[.NET] by iPwnedJun 19, 2016 12:44 PM 6 295 Jun 19, 2016 12:44 PM
Last Post: Odus
[Shell] by HackooApr 5, 2016 11:48 AM 0 138 Apr 5, 2016 11:48 AM
Last Post: Hackoo