I am trying to play MP3 audio in C++ Visual Studio 17.3.0, but keep getting MCIERROR 275 followed by 263.
My .mp3 file is in the same directory as my .cpp file.
My code goes something like this:
MCIERROR me = mciSendString(TEXT("open ""Music.mp3"" type mpegvideo alias mp3"), NULL, 0, NULL);
while(true){
me = mciSendString(TEXT("play mp3"), NULL, 0, NULL);
}
Have tried different .mp3 files, different directory, and different function for playing the sound (PlaySound()), which gave me a very similar result/error.
What could be the cause of my problem?
The first is to open:
mciSendString("open Summer.mp3 alias song",NULL,0,NULL)
Add the relative path or absolute path of the file after open (depending on the relative position of the music you play and your program)
We could understand alias as replacing your music name with the name after alias, which is convenient for us to carry out subsequent operations, only need to enter your alternative name (to save the trouble if the song name is long)
The last three parameters can be written as I do, because we are just simply playing music, so there is no need to go into details.
Next is to play:
mciSendString("play song repeat",NULL,0,NULL);
play+music name (or an alternative name after alias)+[play selection]
Playback options include repeat, wait.
repeat means to repeat the song.
wait means that the function does not return until the song has finished playing.
Related
std::string str1 = "C:\\Users\\user\\Desktop\\Notes";
ShellExecuteA(NULL, "open", str1.c_str(), NULL, NULL, SW_SHOWNORMAL);
The code isn't worth much.
I have an .mp3 in a DJ program. In one of the tags, it holds the filename of the associated video. All the videos are .mpeg.
With the DJ software's API, I can grab the tag. I know where the video files are (all in one folder). I can open the video with ShellExecuteA(), because whilst the tag might not contain the full filename+extension, I know the extension.
Now the problem - I want to start using .avi or .h254 or whatever. I don't know the extension anymore, and ShellExecuteA() needs an extension.
What can I do?
My guesses are:
If ShellExecuteA() returns an error (not sure it does), if it does I could brute-force it; is it .mpeg? Is it .avi? Is it .h264? etc...
Do a search in the known location with the filename missing the extension, and then grab the full filename with whatever it finds (all file names are unique, even excluding the extension).
I know I could add the extension in the .mp3 tag, but there are reasons why I'd rather not do that.
ShellExecute does not need extension. It needs the exact file name. If extensions are hidden in Windows Explorer - make them visible. If you don't know the extension for other reason, use FindFirst with wildcard * (Notes*) to find the full name.
FindFirstA got me the results I wanted
obviously there are more direct ways than sstream but other stuff is going on that isn't important to the actual problem
std::stringstream sstrm1, sstrm2;
sstrm1 << "C:\\Users\\user\\Desktop\\";
sstrm2 << sstrm1.str() << "Notes.*";
HANDLE hFind;
WIN32_FIND_DATAA data;
hFind = FindFirstFileA(sstrm2.str().c_str(), &data);
sstrm1 << data.cFileName;
ShellExecuteA(NULL, "open", sstrm1.str().c_str(), NULL, NULL, SW_SHOWNORMAL);
I want to try and make an MP3 player for Windows. I searched for a function to play audio and found PlaySound() and mciSendString(), from my "research" I found that PlaySound() is only for .wav files, but, for now at least, I want .mp3. I tried mciSendString(), if in the play command, at the end of string I have the parameter "wait"(mciSendString("play audio.mp3 wait", NULL, 0, 0)) then the audio plays fine, but, I can't stop it, I will have to wait(what a surprise) for the audio to end, I found that the wait parameter does that(again, what a surprise). I tried then something like that:
while (!_kbhit()){ //as long as I don't press something
mciSendString("play audio.mp3", NULL, 0, 0); //without the wait
}
I thought that this function might have some sort of pointer that points to where exactly we are in the audio, how much of it we have heard, and with each execution of the command with the same audio, the pointer going, little by little, to the end, to the last "element" of the .mp3 file(note: I don't have the slightest idea how mp3 files and reading from them works)
I seached on the Internet for an example of proper use of mciSendString(), but I couldn't find any clear example/answer or something that works for me, for example, many were saying that still, without the wait it would work, but it didn't. So, here I am now.
What I'm asking: a clear example(code if possible) on how to use mciSendString or other function(s) to do the same thing.
Thank you for listening(reading actually) my problem.
How to play a sound file specified by user in an array using the PlaySound()? I'm using Windows7 and VC++ 2010.
Suppose I use the gets(song); statement to input the complete path of the song from user.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx
PlaySound( song, NULL, SND_FILENAME );
EDIT: Solved. Simply the .wav file was not accepted by Windows. I plucked one of Windows own files and renamed it to what my previous file was called and it plays without problem.
I don't know why this can't play the existing file. Windows gives a chime in that something is wrong but I have no clue what.
I added a check right before to make sure it exists. I have also tried absolute paths.
string wavPath = "c:\\frog.wav";
struct stat stFileInfo;
bool blnReturn = (stat(wavPath.c_str(), &stFileInfo) == 0); //this returns true
FILE* fp = fopen(wavPath.c_str(), "r");
if (fp) {
fclose(fp); //this triggers
}
PlaySound(wavPath.c_str(), NULL, SND_FILENAME | SND_ASYNC); //m_hinstance
//C:\\Users\\Wollan\\My Code\\A\\Debug\\frog.wav
//TEXT("frog.wav")
//TEXT(wavPath.c_str())
//(LPCSTR)"frog.wav¨
The file plays fine in WMP.
This following code perfectly works:
PlaySound(L"C:\\Windows\\Media\\Cityscape\\Windows Balloon.wav", 0, SND_FILENAME );
Adding SND_ASYNC fails to play.
The documentation says:
The pszSound parameter is a file name. If the file cannot be found,
the function plays the default sound unless the SND_NODEFAULT flag is
set.
And:
PlaySound searches the following directories for sound files: the
current directory; the Windows directory; the Windows system
directory; directories listed in the PATH environment variable; and
the list of directories mapped in a network. If the function cannot
find the specified sound and the SND_NODEFAULT flag is not specified,
PlaySound uses the default system event sound instead.
No other case is specified for this outcome.
Therefore, that you hear a chime indicates that the file is not being found, despite your assurances to the contrary.
I'd double-check the result of that stat call; I can't even find stat in the documentation; it doesn't appear to be part of Windows.
PlaySound(L"C:\Windows\Media\Cityscape\Windows Balloon.wav", 0, SND_FILENAME );
Adding SND_ASYNC fails to play.
This answer is right!
It is because the ASYNC mode plays the music after the function returns.
Your code may have exited before the music plays.
use int x, cin>>x, after PlaySound function, you will find that it works well.
I am using FMOD to play some sounds and I would like to save the resulting mix to the disk.
I have been trying the system->recordStart(0, sound, true) path, but that saves the microphone input of the device.
In some way, I would like to redirect the speakers output to the disk
Thank you
Marc
To redirect everything that would go to the speakers to disk simply use the function System::setOutput and pass in a value of FMOD_OUTPUTTYPE_WAVWRITER. Make sure you call this function before you call System::init, when you are done call System::release and a wav file will appear next to your executable.
You can also specify the name and location of the output wav file by passing a full path via the System::init extradriverdata parameter.