[英]How to add an mp3 file as a resource and then play it
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!我正在使用 Visual Studio,我想知道如何将 mp3 文件添加为资源然后播放,但我找不到任何东西!
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:对于 nom 我已将文件添加到资源文件夹但我是否正确执行了我不知道 my.rc 文件有一个名为“mp3”的文件夹,其中是我尝试过的文件 IDR_MP31:
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?我可以用 mciSendString 玩吗?
EDIT : i've got it playing.WAV files from memory but this isn"t ideal as it takes alot of memory编辑:我已经开始播放 memory 中的 WAV 文件,但这并不理想,因为它需要大量 memory
in resource.h:在资源.h 中:
#define IDR_WAVE1 104
function 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.如果有人知道如何以这种方式播放 mp3 文件,请告诉我。 thanks谢谢
You should be able to play it with mciSendString: mciSendString("play mp3", NULL, 0, NULL);
您应该可以使用 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这个链接也有一些有用的信息: https://www.codeproject.com/Articles/17279/Using-mciSendString-to-play-media-files
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.