hello! it is possible to play sound in C ?
outside the function Beep ()?
I want to play a "*.wav" or "*.mp3" , if that is possible
Le.:I use windows xp sp2 + codeblocks with mingw
hello! it is possible to play sound in C ?
outside the function Beep ()?
I want to play a "*.wav" or "*.mp3" , if that is possible
Le.:I use windows xp sp2 + codeblocks with mingw
Last edited by nutzu2010; 01-01-2011 at 03:30 AM.
Yes. Ask Google how.
Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.
Code:#include <windows.h> #include <stdio.h> int main() { PlaySound("c:\\bird.wav", NULL, SND_ASYNC); return 0; }
This error occurs:
Code:Compiling: C:\Documents and Settings\i'm vochin\My Documents\code blocks project's\teste\Untitled2.c Linking console executable: C:\Documents and Settings\i'm vochin\My Documents\code blocks project's\teste\Untitled2.exe C:\Documents and Settings\i'm vochin\My Documents\code blocks project's\teste\Untitled2.o:Untitled2.c:(.text+0x42): undefined reference to `_PlaySoundA@12' collect2: ld returned 1 exit status Process terminated with status 1 (0 minutes, 0 seconds) 1 errors, 0 warnings
Close. Although you have included the appropriate header file, the matching library is not being linked in automagically, as is the case with standard headers.
You said that you're using MinGW. In that case, all you need to do is add "-lwinmm" to your compile options.
If you were compiling purely from CLI, it would look something like this:
Code:gcc play_sound.c -lwinmm
Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.
sorry to ask such a silly, but how do I add "-lwinmm" in compiler options?
settings->compiler and debugger settings ,and now?
I have no experience with Code::Blocks. I'd hazard a guess and suggest that you look under Project/Build or equivalent. Maybe someone who has worked with C::B will come along and give you a hint.
Alternatively, you could compile from CLI.
Code:Windows > Run > "cmd" cd /d "C:\Documents and Settings\i'm vochin\My Documents\code blocks project's\teste\" gcc Untitled2.c -oplay_sound -lwinmm play_sound.exe
Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.
does anybody know how to play a sound using linux instead of windows.
thanks
Yes, you google "linux sound" or "linux audio". I would have thought that obvious enough to have tried before posting (or hijacking someone else's thread).
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
i have add to "Linker options":
and i have the error:Code:gcc play_sound.c -lwinmm
Code:Compiling: C:\Documents and Settings\i'm vochin\My Documents\code blocks project's\teste\Untitled2.c Linking console executable: C:\Documents and Settings\i'm vochin\My Documents\code blocks project's\teste\Untitled2.exe C:\Program Files\CodeBlocks\MinGW\bin\ld.exe: cannot find -lgcc play_sound.c -lwinmm collect2: ld returned 1 exit status Process terminated with status 1 (0 minutes, 0 seconds) 1 errors, 0 warnings
So, "gcc play_sound.c -lwinmm" is a long way off from "winmm" I should think.
I wanted to put "-lwinmm"
thanks!worked!