How Do I Play Sound in C++ Bloodshed

I would like to get a source code that shows the example.

Page 1 of 1

5 Replies - 4004 Views - Last Post: 23 November 2009 - 10:38 AM Rate Topic: -----

#1 Guest_Blatnoi*


Reputation:

How Do I Play Sound in C++ Bloodshed

Posted 23 November 2009 - 09:13 AM

#include <iostream>
#include <windows.h>


using namespace std;
int main()
{
    //I have tried thouse and they open it in the wmp. Is there a way to make
    //it in the cmp?
    
    cout << "sound" << endl;
    
   // PlaySoundA("F:\\flash\\CsC 160\\bugsbunny1.wav", );
    PlaySound("beback.mp3", NULL, SND_FILENAME|SND_LOOP);
    //PlaySound(TEXT("F:\\flash\\CsC 160\\bugsbunny1.wav"), NULL, SND_FILENAME);
    
    //system("F:\\flash\\CsC 160\\bugsbunny1.wav");
    
system("pause");
return 1;
}


*** MOD EDIT : Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 23 November 2009 - 09:29 AM


Is This A Good Question/Topic? 0

Replies To: How Do I Play Sound in C++ Bloodshed

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,663
  • Joined: 23-August 08

Re: How Do I Play Sound in C++ Bloodshed

Posted 23 November 2009 - 09:30 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 Guest_Blatnoi*


Reputation:

Re: How Do I Play Sound in C++ Bloodshed

Posted 23 November 2009 - 09:34 AM

it tells me
[Linker error] undefined reference to `PlaySoundA@12'
ld returned 1 exit status
Was This Post Helpful? 0

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,663
  • Joined: 23-August 08

Re: How Do I Play Sound in C++ Bloodshed

Posted 23 November 2009 - 09:42 AM

You need to add winmm.lib (I think) to the list of libraries to link into the executable. How you do that on Dev-C++ is not taking any space up in my brain, so I can't help you further in that respect.
Was This Post Helpful? 0
  • +
  • -

#5 Guest_Blatnoi*


Reputation:

Re: How Do I Play Sound in C++ Bloodshed

Posted 23 November 2009 - 10:18 AM

well thank you anyway
Was This Post Helpful? 0

#6 Guest_Blatnoi*


Reputation:

Re: How Do I Play Sound in C++ Bloodshed

Posted 23 November 2009 - 10:38 AM

I also tried this and gives me error
[Linker error] undefined reference to `PlaySoundA@12'
ld returned 1 exit status


#include <cstdio> // getchar()
#include <windows.h> // PlaySound()

using namespace std;

int main()
{
char soundfile[] = "F:\\flash\\CsC 160\\bugsbunny1.wav";
PlaySound(soundfile,NULL,SND_FILENAME|SND_ASYNC);

getchar(); // wait
return 0;
}

This post has been edited by Blatnoi: 23 November 2009 - 10:39 AM

Was This Post Helpful? 0

Page 1 of 1