Thread: Music on a program

  1. #1
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90

    Question Music on a program

    Hey can I add music to my program without having the music file?
    Like kinda build music into the .exe?
    Just like a install program. All the files are in the install.exe

    And,
    How do I remove the the DOS window?
    I got a full screen code, but the little DOS window is still running in the background.
    Last edited by XunTric; 09-27-2005 at 10:04 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Sure, which OS and compiler are you using?
    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.

  3. #3
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    Windows XP: Home Edition.
    Dev-C++ (Cpp)

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Try a board search
    Search: Key Word(s): PlaySound ; Forum: Windows Programming and child forums
    Showing results 1 to 25 of 32
    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.

  5. #5
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    Child forums... hmm.... :P
    Well ill see if I find something.

  6. #6
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    Alright, why isnt this working?
    Code:
    #include <windows.h>
    #include <Mmsystem.h>
    
    #pragma comment(lib, "winmm.lib")
    
    int main(void)
    {
        PlaySound("test.mp3",  NULL, SND_ASYNC | SND_FILENAME);
    }
    Thats not my code of course...
    Just the music part.

  7. #7
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Well that's not working because you are using Dev-C++. You are using the MS Visual C++ way to link a library. Take out that "#pragma comment" line and go to tools>>compiler options>>and under the compiler tab write -lwinmm in the box that says add these commands to the linker command line. Now the library is linked and it compiles.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  8. #8
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    Thanks it compiles now =D
    But the music dont start.
    I just found a song and called it test (.mp3), then placed it in the same folder as my program.
    Whats wrong now?

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Whats wrong now?
    Well did you check the return result, and did you turn on your speakers / turn the volume up?
    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.

  10. #10
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    >> turn on your speakers / turn the volume up?
    Lol, yes of course-

    All I get its a "beep" from the computer when I start the program.
    You know when you press all buttons at the same time on your keyboard then you get this annoying error "beep" from your computer.

    >>Return result
    Ehm... The compiler log? No errors or warnings?

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    As in
    bool success = PlaySound("test.mp3", NULL, SND_ASYNC | SND_FILENAME);
    if ( !success ) crashandburn();

    Or words to that effect.
    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.

  12. #12
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    crashandburn();
    lolz

    please answear serius?

  13. #13
    Registered Loser nickodonnell's Avatar
    Join Date
    Sep 2005
    Location
    United States
    Posts
    33
    I think he was serious. He meant write something to check and see if the file plays, and if not bla bla...
    ------------------------------------------------
    cout<<"Hello World!\n";
    ------------------------------------------------

  14. #14
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    Code:
    bool success = PlaySound("test.mp3", NULL, SND_ASYNC | SND_FILENAME);
        
    if(!success) {
         MessageBox(HWND_DESKTOP,"Could not find test.mp3","",MB_OK);
         return 1;
    }
    I see no error box...

  15. #15
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    In my experience, when you are compiling something and that something tried to access a file, unless you specify the entire path, it will look in your PWD ( present working directory) which to me means that it is going to be looking for the file in the same spot your cpp is, and not the same spot as your exe.
    I could be wrong, havn't tested it or such.

    If you want to be certain you can play a file, and worry about flexibility later, then just place your mp3 in your root, and use the entire file path to play it.


    Also make sure your function can play an MP , i'm not sure what PlaySound can do

    go here..
    http://msdn.microsoft.com/library/de..._playsound.asp


    .... From MSDN
    The sound specified by pszSound must fit into available physical memory and be playable by an installed waveform-audio device drive.
    PlaySound searches the following directories for sound files: the current directory; the Windows directory; the Windows system directory; directories listed in the PATH environment variable; and the list of directories mapped in a network

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Music Programming - Serial Matrix Display (Help needed)
    By CrazyHorse in forum C Programming
    Replies: 1
    Last Post: 11-13-2007, 04:28 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 10:49 PM
  4. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM