How do you play sounds in a console app. I don't care if wave or mp3, or both. I can always convert...
Id like to be able to play gun shots and music in a console app, and sometimes at the same time if so.
Tahnx.
How do you play sounds in a console app. I don't care if wave or mp3, or both. I can always convert...
Id like to be able to play gun shots and music in a console app, and sometimes at the same time if so.
Tahnx.
Look up PlaySound() on MSDN.
It says this, but isnt clear on what file types and weather or not to set a path.
Also I want to keep it normal C syntax. And do I include anything?
http://msdn.microsoft.com/library/de.../PlaySound.asp
That's not the right playsound it's here
http://msdn.microsoft.com/library/de..._playsound.asp
And it accepts .wav files
If you meant that you wanted to stick to standard c then you're out of luck since the c standard doesn't support sound.
Last edited by Quantum1024; 05-22-2006 at 08:33 PM.
Ok this compiles but it does nothing. Well of course it doesnt, i dont even think I have a file called this, but can anyone explain what this really means in each line. Like how would I load a .wav file from ANYWHERE in the computer?
Code:#include <Mmsystem.h> #include <iostream> #pragma comment(lib,"Winmm.lib") PlaySound("Music", 0, SND_RESOURCE | SND_NODEFAULT);
According to the docs, PlaySound will search the following directories for the file.
Need any more? Or do you just mean like, specifying the direct path to a file on the computer? In that case, you can say that the file would be something like "C:\\Blah\\Blue\\Blee\\Brew.wav"1. The directory where an application is loaded.
2. The current directory.
3. The Windows system directory.
4. The 16-bit Windows system directory.
5. The Windows directory.
6. The directories that are listed in the PATH environment variable.
yes but what does the 0 mean in "Music",0
and also is "music" just mean the title of the file I want it to find?
also where would I exactly define where I want for it to find the file?
sorry im new.
Where "music" is you would put your filename for example "sound.wav". The second paramater can be left as 0 as it is for playing a sound from a resource inside an executable module. The third should use SND_FILENAME if you want to play from a file SND_RESOURCE plays a sound from a resource
Code:PlaySound("C:\\Sound.wav", 0, SND_FILENAME | SND_NODEFAULT);
Read the PlaySound documentation.
In your case, first param would be a filename, second is NULL or 0, third would be SND_FILENAME | SND_NODEFAULT specifying that it is a filename and that a default should not be played.PlaySound
The PlaySound function plays a sound specified by the given filename, resource, or system event. (A system event may be associated with a sound in the registry or in the WIN.INI file.)
BOOL PlaySound(
LPCSTR pszSound,
HMODULE hmod,
DWORD fdwSound
);
Parameters
pszSound
A string that specifies the sound to play. The maximum length, including the null terminator, is 256 characters. If this parameter is NULL, any currently playing waveform sound is stopped. To stop a non-waveform sound, specify SND_PURGE in the fdwSound parameter.
Three flags in fdwSound (SND_ALIAS, SND_FILENAME, and SND_RESOURCE) determine whether the name is interpreted as an alias for a system event, a filename, or a resource identifier. If none of these flags are specified, PlaySound searches the registry or the WIN.INI file for an association with the specified sound name. If an association is found, the sound event is played. If no association is found in the registry, the name is interpreted as a filename.
hmod
Handle to the executable file that contains the resource to be loaded. This parameter must be NULL unless SND_RESOURCE is specified in fdwSound.
fdwSound
Flags for playing the sound. The following values are defined.
...
Ok it played, but it freezes all of my actions.
I want to be able to type in my _getche()'s while it plays, instead it pauses the program, and it DOESNT even play ALL of the file, only like dirst 20 secs of it.
Help be appreciated thanx.
Code:PlaySound("C:\\Finale.wav", 0, SND_FILENAME | SND_NODEFAULT);
Add the SND_SYNC flag.
Ok, that works, but lets say I wanted to play two .wav files, or even more... at the same time?
Code:PlaySound("C:\\Wipala.wav", 0, SND_FILENAME | SND_NODEFAULT | SND_ASYNC); PlaySound("C:\\Finale.wav", 0, SND_FILENAME | SND_NODEFAULT | SND_ASYNC);
And also lets say I want to STOP a sound at will?
I've tryed various possiblities of the MSDN, but whats the best way? thanx, this will be useful.
>>want to STOP a sound at will
>>I wanted to play two .wav filespszSound
A string that specifies the sound to play. The maximum length,
including the null terminator, is 256 characters. If
this parameter is NULL, any currently playing waveform sound is
stopped. To stop a non-waveform sound, specify
SND_PURGE in the fdwSound parameter.
Sciences are vain and full of errors, which do not spring from
experiment, the source of all certainty.
Leonardo DaVinci
[edit]
Dosn't this belong on the windows board?
[/edit]
No No's:
fflush (stdin); gets (); void main ();
Goodies:
Example of fgets (); The FAQ, C/C++ Reference
My Gear:
OS - Windows XP
IDE - MS Visual C++ 2008 Express Edition
ASCII stupid question, get a stupid ANSI
I have read that playing two sounds with playsound() at the same time is impossible since it is asynchronously.
So what do I do!?!