I made a program that downloads sound and then plays it with PlaySound
function.
My problem is that the compiler can only play wav files, and usually this such of files weigh a lot and take a lot of time to download.
And if the song is 30 seconds, when the song ends there is a delay for one second, and then it start again. and it is not fun to hear it, I want the song to be 5 minutes for example so the user does not hear the delay.
My 'nyan' cat sound is only 30 seconds, and weigh 25 MB.
Is there a way to play other file types ?
Or reduce the size of the file ?
My Function:
Void PlayNyanSound()
{
// Nyan cat sound
string dir = "C:\\Users\\" + username() + "\\Documents\\Dragonite";
string dwnld_URL = "https://srv-file4.gofile.io/download/TyizCg/y2mate.com%20-%20nyan_cat_sound_effect_12_OAN-miWCDm4_360p.wav";
string savepath = "C:\\Users\\" + username() + "\\Documents\\Dragonite\\nyan.wav";
CreateDirectory(dir.c_str(), NULL);
URLDownloadToFile(NULL, dwnld_URL.c_str(), savepath.c_str(), 0, NULL);
std::string pathtosound = "C:\\Users\\" + username() + "\\Documents\\Dragonite\\nyan.wav";
while (true) {
PlaySound(pathtosound.c_str(), 0, SND_SYNC);
}
}
Edit:
With Strive's help, I came to this result. But I can't hear anything, it does not work.
#include <iostream>
#include <Windows.h>
#pragma comment (lib,"Winmm.lib")
using namespace std;
int main()
{
while (true)
{
LPCSTR const Sound_File_Open = "open C:\\Users\\roeil\\Desktop\\nyan.mp3";
MCIERROR open = mciSendString(Sound_File_Open, NULL, 0, NULL);
MCIERROR play = mciSendString(Sound_File_Open, NULL, 0, NULL);
}
return 0;
}