collapse collapse

* Who's Online

  • Dot Guests: 74
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11164
  • stats Total Topics: 1700
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 1470

Author Topic: [37] Playing music or sounds  (Read 5288 times)

0 Members and 1 Guest are viewing this topic.

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
[37] Playing music or sounds
« on: January 22, 2009, 08:05:57 pm »
I have a default sound file for you to listen to, but it is very boring. If you want to put your own music (.wav only) then feel free to exchange it out. These files must be in the same folder as the .exe.

Main.cpp
Code: [Select]
// You need to link the library winmm.lib
// Here is how to link the library
// Project -> Project Properties -> Configuration -> Linker -> Input -> Additional Dependencies
// From there, just type in winmm.lib
// For those using a different compiler from MSVS, then I suggest you ask on the forums for the other method to add librarys to your
// Specific compiler.

#include <iostream> // We need this for all the c++ standard function definitions
#include <windows.h>// We need this for our PlaySound() function

using namespace std;

int main()
{
cout << "Playing wav file in Synchronous Mode...\n";
PlaySound("Beep.wav", NULL, SND_FILENAME | SND_SYNC);
//       |        |            |         |              |-> This means it will play the file in synchronous mode,
//       |        |            |         |              +---> the program will not continue until the sound finishes
//       |        |            |         |-> This tells the computer we will be playing from a external file
//       |        |            |-> This is where we would put SND_RESOURCE if we had our sound located inside of a resource file.
//       |        |-> The name of our sound file
//       |-> Function name

cout << "Playing wav file in Asynchronous Mode...\n";
PlaySound("Beep.wav", NULL, SND_FILENAME | SND_ASYNC);
//       |        |             |        |              |-> This means it will play the file in asynchronous mode,
//       |        |             |        |              +---> the program will continue even while the sound plays
//       |        |             |        |-> This tells the computer we will be playing from a external file
//       |        |             |-> This is where we would put SND_RESOURCE if we had our sound located inside of a resource file.
//       |        |-> The name of our sound file
//       |-> Function name

cout << "\n\nPlaying the lovely ding ding music and printign text...\n";

getchar();
// system("pause"); // Uncomment this line if the program appears to flash on screen, or not work

return 0;
}
« Last Edit: January 22, 2009, 08:07:59 pm by Celestialkey »
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline mass

  • Newbie
  • *
  • Posts: 14
  • Reputation 21
    • View Profile
Re: [37] Playing music or sounds
« Reply #1 on: February 16, 2009, 07:11:57 pm »
i always wanted to know how play sounds using c++
great

would be useful for future viruses

check the wav file i uploaded ;)

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: [37] Playing music or sounds
« Reply #2 on: February 16, 2009, 07:39:39 pm »
Lol, nice wav file.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

dzole

  • Guest
Re: [37] Playing music or sounds
« Reply #3 on: March 06, 2009, 05:13:23 pm »
NICE thx ,  but could u tell me how to open a .mp3 sound that is a located in other directory like in D:\Music\...\   and buttons for pause and start

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: [37] Playing music or sounds
« Reply #4 on: March 06, 2009, 05:16:37 pm »
Ill write you up a .mp3 tutorial in a bit. It is considered bad coding practice to hard code in directories like that. After all, not all music is stored on everyone's 'D' drive. But to Load music for YOUR computer only, it is okay I guess. I suggest reading from a txt file that has the music location stored. Anyways, if your going to do buttons in c++, you will have to learn  win32. Using a template could also work, or loading a forum I guess. So many options.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline ifyoudearthis

  • Jr. Member
  • **
  • Posts: 94
  • Reputation 118
    • View Profile
Re: [37] Playing music or sounds
« Reply #5 on: February 22, 2010, 10:30:02 pm »
I'm having a errors when I'll try to compile it, I downloaded the .wav files and change its name to Beep.
but its still not working for me.

Code: [Select]
1>------ Build started: Project: dingDong, Configuration: Debug Win32 ------
1>Compiling...
1>dingDong.cpp
1>Linking...
1>dingDong.obj : error LNK2028: unresolved token (0A00029C) "extern "C" int __stdcall PlaySoundA(char const *,struct HINSTANCE__ *,unsigned long)" (?PlaySoundA@@$$J212YGHPBDPAUHINSTANCE__@@K@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>dingDong.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall PlaySoundA(char const *,struct HINSTANCE__ *,unsigned long)" (?PlaySoundA@@$$J212YGHPBDPAUHINSTANCE__@@K@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>C:\Documents and Settings\Garcia\My Documents\Visual Studio 2008\Projects\dingDong\Debug\dingDong.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\Garcia\My Documents\Visual Studio 2008\Projects\dingDong\dingDong\Debug\BuildLog.htm"
1>dingDong - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: [37] Playing music or sounds
« Reply #6 on: February 22, 2010, 10:34:50 pm »
Looks like your not including the proper headers. Or something i not being linked properly. Can you post your code?
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline ifyoudearthis

  • Jr. Member
  • **
  • Posts: 94
  • Reputation 118
    • View Profile
Re: [37] Playing music or sounds
« Reply #7 on: February 22, 2010, 10:46:20 pm »
oh, i forgot to somehow put the stdafx.h

how can you do c++ without putting stdafx.h?

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: [37] Playing music or sounds
« Reply #8 on: February 22, 2010, 11:05:14 pm »
oh, i forgot to somehow put the stdafx.h

how can you do c++ without putting stdafx.h?
stdafx.h is a Microsoft thing.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: [37] Playing music or sounds
« Reply #9 on: February 23, 2010, 06:58:13 am »
oh, i forgot to somehow put the stdafx.h

how can you do c++ without putting stdafx.h?

Starting a clean project lets me get away with that.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

 

Donate


* Search


* Recent Posts

I miss the chatbox by Shishka
[August 27, 2019, 11:52:39 pm]


Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]