1,105,208 Community Members

Playsound funtion not working DEV-C++

Member Avatar
thecoolman5
Posting Whiz in Training
245 posts since Dec 2010
Reputation Points: 8 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hi, i have written this code.

#include<iostream>
#include<windows.h>
#include<mmsystem.h>
#include<stdlib.h>
using namespace std;
int main (char argc)
{
      PlaySound("TardisTest1.wav", NULL, SND_FILENAME | SND_ASYNC);
      system("pause");
      return 0;
}

and for some reason, when the program runs, all it does is system("pause); and it doesnt play the sound. I have my sound file included in the folder of my project. any solutions?

Member Avatar
Moschops
Nearly a Posting Virtuoso
1,363 posts since Sep 2008
Reputation Points: 414 [?]
Q&As Helped to Solve: 266 [?]
Skill Endorsements: 16 [?]
Featured
 
0
 

Try ensuring that you're passing the right kind of variable, by wrapping the string as follows:

PlaySound(TEXT("TardisTest1.wav"), NULL, SND_FILENAME | SND_ASYNC);

The project directory is not guaranteed to be the working directory of the executable. Try giving an absolute path (e.g. "C:/TardisTest1.wav").

Also, PlaySound gives a return value. Check that value to see if the function was successful.

Do you hear any sound at all? If the function can't find the file, you should hear the default sound.

Member Avatar
thecoolman5
Posting Whiz in Training
245 posts since Dec 2010
Reputation Points: 8 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

ok, that got it to work. now, is there any way to play an ogg audio file?

Member Avatar
Moschops
Nearly a Posting Virtuoso
1,363 posts since Sep 2008
Reputation Points: 414 [?]
Q&As Helped to Solve: 266 [?]
Skill Endorsements: 16 [?]
Featured
 
0
 

I'd suggest stepping away from directly using the Win API. Try SFML.

http://www.sfml-dev.org/tutorials/1.6/audio-sound.php

Also, Dev-C++ is bad. Really quite bad. There are far better alternatives.

http://www.cplusplus.com/forum/articles/36896/

Member Avatar
thecoolman5
Posting Whiz in Training
245 posts since Dec 2010
Reputation Points: 8 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Well, I have been using DEV-C++ ever since I was 10 years old and I don't want to give up on it now. But thanks for helping me.

Question Answered as of 2 Years Ago by Moschops
Member Avatar
Moschops
Nearly a Posting Virtuoso
1,363 posts since Sep 2008
Reputation Points: 414 [?]
Q&As Helped to Solve: 266 [?]
Skill Endorsements: 16 [?]
Featured
 
0
 

"I have been using DEV-C++ ever since I was 10 years old"

That makes me wince. We don't say it's bad just for the fun of it. It really is bad. Just because you've learned how to work around all the problems doesn't mean you can't get something better.

Member Avatar
thecoolman5
Posting Whiz in Training
245 posts since Dec 2010
Reputation Points: 8 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Well, I would rather prefer to stick to what I'm use to.

Member Avatar
Moschops
Nearly a Posting Virtuoso
1,363 posts since Sep 2008
Reputation Points: 414 [?]
Q&As Helped to Solve: 266 [?]
Skill Endorsements: 16 [?]
Featured
 
0
 

Of course, of course. It's entirely your choice to use, for example, a compiler that is not C++ standard compliant. Be aware that if you ever have to work with another compiler, you might find that your code stops working. It is possible to continue using Dev-C++ and swap out the compiler for a better one, so that's always an option.

Member Avatar
thecoolman5
Posting Whiz in Training
245 posts since Dec 2010
Reputation Points: 8 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Ok.

Member Avatar
thecoolman5
Posting Whiz in Training
245 posts since Dec 2010
Reputation Points: 8 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

One more thing, how do you get the audio to speed up?

Member Avatar
thecoolman5
Posting Whiz in Training
245 posts since Dec 2010
Reputation Points: 8 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

And how do you get it to play two songs at the same time?

Member Avatar
m4ster_r0shi
Posting Whiz in Training
283 posts since Mar 2010
Reputation Points: 142 [?]
Q&As Helped to Solve: 42 [?]
Skill Endorsements: 3 [?]
 
0
 

You can't do that with PlaySound. If you want that kind of functionality you need a library like OpenAL or SDL or SFML etc...

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: