UPDATE: The title of this topic has changed. I have managed to fix the first problem I was having, only to be greeted by another. I will copy/paste the current problem here to save you from having to go through the dialogues below:
1 2 3 4 5 6 7
void playAudio(char* audioFile)
{
mciSendString(L"open " + audioFile + " type waveaudio alias song", NULL, 0, 0); // Doesn't work, cannot add const char* to another char*
mciSendString(L"play song wait", NULL, 0, 0);
mciSendString(L"close song", NULL, 0, 0);
}
...And yeah, that's pretty much the problem. Quite simple, just trying to concatenate things together to form a full path.
OLD: Hello, so I am trying to build a multi-threaded audio player, but first I need to figure out why mciSendString not playing any of my files. Below is how I'm using it, and according to MSDN that's how you should be using it. Where am I going wrong?
Hey Thomas, I did that, thank you so much. I was able to find out what the problem was. Turns out I needed to specify the type of the file, in my case it's a waveaudio file. Now that I got it to work with a hard-coded file, I'm having another issue. So basically I want the user to be able to select as many audio files they want and I want all of them to play concurrently. The multi-threading part is easy, but squeezing in the file name inside the mciSendString function I'm finding a bit challenging. Here's an example of what I'm having trouble with:
1 2 3 4 5
char* audio = C:\\Test\\bird.wav;
mciSendString(L"open " + audio + " type waveaudio alias song", NULL, 0, 0);
mciSendString(L"play song wait", NULL, 0, 0);
mciSendString(L"close song", NULL, 0, 0);
Alright, I'll give this piece of code a shot. Also I agree, but I need my application to be multi-threaded and I do not think PlaySound is eligible for multi-threaded behavior.
Err... This doesn't seem to work as mciSendString only accept 4 parameters and not 5. Also for some reason in the string audio = "open " + "C:\\Test\\bird.wav"; when I hover my cursor on the C:\\Test\\bird.wav it reads "expression must have integral or unscoped enum type" this is driving me crazy... Even the audioc_str() reads "argument of type "const char*" is incompatible with parameter of type "LPCWSTR".
Can you give me an example of two or more PlaySound functions firing at the same time? Because this was my earlier attempt and it didn't seem to do it:
Took quite some thinking but I'm happy it's working now. If you do not intend to have your program play two audio files at once, you're better off using the PlaySound() function instead. I decided to use the mciSendStringA() function for multi-threaded behavior.