473,223 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,223 software developers and data experts.

Playsound Function

Why won't the following code work?

char soundfile2[] = "C:/Windows/Media/pinky and the
brain.wav";

PlaySound(soundfile2,NULL,SND_FILENAME|SND_SYNC|SN D_ASYNC);
getchar();

i put libwinmm.a in the parameters and i have all the right headerfiles
in there, but it won't work. it says that i must declare SND_FILENAME ,
SND_SYNC and everything else in the second line. It works perfectly in
a console application but it doesn't seem to work in a glut
application. BTW, im using namespace std.
can someone please help me out.

Aug 16 '05 #1
19 15371
bballmitch wrote:
Why won't the following code work?

char soundfile2[] = "C:/Windows/Media/pinky and the
brain.wav";

PlaySound(soundfile2,NULL,SND_FILENAME|SND_SYNC|SN D_ASYNC);
getchar();

[...]


There is no 'PlaySound' function in Standard C++, which is incidentally
the only subject of this newsgroup. Please try a newsgroup for your
platform if it supports playing sound.

Also, as a side note, the directory name separator in Windows is not
the '/' symbol but the '\' symbol, which also needs to be doubled when
put in a string literal. You might want to try

char soundfile2[] = "C:\\Windows\\Media\\pinky and the brain.wav";

V
Aug 16 '05 #2
you want to bet there's no playsound function? i know for a fact there
is cause i've used it. but it won't work in an OpenGL file, only
console application. i need help, so don't talk about what you don't
know. those three lines EXACTLY work in Dev C++ console application.

Aug 16 '05 #3
* bballmitch:
you want to bet there's no playsound function? i know for a fact there
is cause i've used it. but it won't work in an OpenGL file, only
console application. i need help, so don't talk about what you don't
know. those three lines EXACTLY work in Dev C++ console application.


As we all know it's september.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Aug 16 '05 #4
"bballmitch" <lu*********@sbcglobal.net> wrote in
news:11*********************@g49g2000cwa.googlegro ups.com:
you want to bet there's no playsound function? i know for a fact there
is cause i've used it. but it won't work in an OpenGL file, only
console application. i need help, so don't talk about what you don't
know. those three lines EXACTLY work in Dev C++ console application.


Yep. I will bet you that there is no playsound (or PlaySound) function
defined in Standard C++. This is comp.lang.c++, where the topic is
Standard C++. You're talking about some 3rd party library. You're much
better off asking in a newsgroup specific to the library and/or platform
that you are using.
Aug 16 '05 #5
bballmitch wrote:
you want to bet there's no playsound function? i know for a fact there
is cause i've used it. but it won't work in an OpenGL file, only
console application. i need help, so don't talk about what you don't
know. those three lines EXACTLY work in Dev C++ console application.


*plonk*

Brian
Aug 16 '05 #6
I'll bet you MY LIFE there is. just type "playsound function in C++"
into google and watch like 10 links to information stating that the
playsound function is used in C++.

Aug 17 '05 #7
bballmitch wrote:
I'll bet you MY LIFE there is. just type "playsound function in C++"
into google and watch like 10 links to information stating that the
playsound function is used in C++.


YES, there IS such a function! Look up its usage in the documentation.
If it still won't work, make sure your loudspeakers are turned on, and
pluged in. If there's still no sound, by a new soundcard. If that
won't help either, try Pascal instead of C++; it has a more compatible
playsound function (supports DirectX, Paula chip, and other stuff).
Aug 17 '05 #8
On Tue, 2005-08-16 at 15:45 -0700, bballmitch wrote:
you want to bet there's no playsound function? i know for a fact there
is cause i've used it. but it won't work in an OpenGL file, only
console application. i need help, so don't talk about what you don't
know. those three lines EXACTLY work in Dev C++ console application.


So, if I happen to make my own little collection of
functions for my own private robot project and name
one of the functions 'StartRightWheel', then that
function is automatically part of the C++ standard?

Note that I _am_ able to use it...

I am willing to bet that there is _no_ function called
'StartRightWheel' in the C++ standard.

--
Mvh / Regards
Rein Anders Apeland

Aug 17 '05 #9
I'll bet you MY LIFE there is.


OK. I'll come get it ;)
BTW: Don't cross post (especially not to c.l.c++ and c.g.a.opengl for
a question that is related to comp.os.ms-windows.programmer.win32

-Gernot
Aug 17 '05 #10
In message <fE*******************@newsread1.mlpsca01.us.to.ve rio.net>,
Victor Bazarov <v.********@comAcast.net> writes
Also, as a side note, the directory name separator in Windows is not
the '/' symbol but the '\' symbol,


Only for the command-line interface. Everywhere else the '/' works fine.

To maintain marginal on-topicality, the following will work (provided
the named file actually exists ;-) in a Windows environment:

#include <istream>
#include <fstream>
int main()
{
std::ifstream s("C:/Windows/Media/pinky and the brain.wav");
// do something with s
}

--
Richard Herring
Aug 17 '05 #11
its not that its not playing sound, it won't compile. :(

Aug 17 '05 #12
bballmitch wrote:
its not that its not playing sound, it won't compile. :(


Which is probably because you are using the 3rd-party function without
including the constants that it defines. Now, as stated earlier, you
have two options for troubleshooting this:

A. Go to a newsgroup that discusses it (NOT the C++ newsgroup which
only deals with C++ and STL, which PlaySound is part of.)

B. Look at the documentation for how to use the function, or the result
of the google searches that you gave up your life for.

Aug 17 '05 #13
Josh Mcfarlane wrote:
[...]
A. Go to a newsgroup that discusses it (NOT the C++ newsgroup which
only deals with C++ and STL, which PlaySound is part of.)
Should probably be "which PlaySound isn't part of"...
[..]

Aug 17 '05 #14
Victor Bazarov wrote:
Should probably be "which PlaySound isn't part of"...


Doh! Typo for the win. Indeed that n't is the most important part.

Aug 17 '05 #15
thank you, just one question though.......what do you mean do
something with s? suppose i just want it to play that song, what do i
put? that compiles but it wont' play(and im playing music on my
computer right now, so its not my computer). if you could just tell me
what to put in that "do something" line, i'll be set. thanks.

Aug 17 '05 #16
bballmitch wrote:
thank you, just one question though.......what do you mean do
something with s? suppose i just want it to play that song, what do i
put? that compiles but it wont' play(and im playing music on my
computer right now, so its not my computer). if you could just tell me
what to put in that "do something" line, i'll be set. thanks.


The C++ Library does not even require your computer to have a monitor,
much less speakers.

What you do with s is dependant upon your 3rd-party library, which is
what we've been trying to tell you. In order to find out what to do
with s, you will have to refer to another newsgroup dealing with your
function or it's documentation.

Aug 17 '05 #17
in C++ what would you do?

Aug 17 '05 #18
bballmitch wrote:
in C++ what would you do?


Use a third-party library, since C++ itself or its standard library
doesn't deal with sound.

/David
Aug 17 '05 #19
bballmitch wrote:
in C++ what would you do?


I believe that "\a" is defined in the standard.

You can just wrap the code to decode the stream around
sleep's and 'std::cout << "\a";' to approximate your
audio stream.

Let us know how it works out.

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Aug 29 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ben Bateman | last post by:
I am tyring to write a small menu program that will display the lyrics of a song, and then play the song. I was told that you have to convert the mp3 to wav, did that. The 2 function calls...
5
by: MLH | last post by:
I have a line of code that works when called from a procedure in Access 2.0 form... PlaySound("C:\cr\help\Help0018.wav", 0) I imported what I thought was needed into A97. However, running it...
4
by: rcattral | last post by:
Has anybody been using the PlaySound() function to play WAV files from within a DLL? Here is what I normally do. Since upgrading to 7.1 NET after using VC 6.0 for quite some time, I found that I...
10
by: Ot | last post by:
I found information on PlaySound. I implemented it in my program and it works just dandy. The only little problem is that I have to package the ..wav files and send them along since PlaySound...
9
by: Andy | last post by:
Hi, I have an application that has several forms. Each form acts as a monitor of a gateway system. If the gateway appears to be dead, the application should play a .wav file (not resource)...
3
by: Jared | last post by:
I'm using the first code sample below to play WAV files stored as embedded resources. For some reason I *occasionally* get scratching and crackling. I'm using a couple WAVs that ship with...
4
by: Cogito | last post by:
Chaps and Chapettes, Program in C++. Im doing a project to detect a defined marker, then play the relevent sound when it can no longer be seen. It worked well when using the beep function. ...
0
by: poppy | last post by:
I tried to play a wav file with function Playsound() but it played only the first seconds of the song.I would like to play whole the song.What might de be wrong?Here is my code in case someone can...
4
by: DumRat | last post by:
Hi, I'm currently interested in playing a sound in win32 API. I found out that the function PlaySound() does pretty well. However, none of the examples I have seen specify how to use...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.