Music on a program

This is a discussion on Music on a program within the C++ Programming forums, part of the General Programming Boards category; I have the cpp, exe and text.mp3 in the same folder. I didnt really get it. How can the program ...

  1. #16
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    I have the cpp, exe and text.mp3 in the same folder.

    I didnt really get it.
    How can the program know which song to play with this example code:
    Code:
    BOOL PlaySound(
      LPCSTR pszSound,  
      HMODULE hmod,     
      DWORD fdwSound    
    );
    I'll try to put it in the root now then.

  2. #17
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    I played around, since i saw you were active.
    PlaySound will not play a .mp3 from my experience.

    I used a .wav, also i placed it in the same place as my .cpp and it works fine.

    What you quoted is a function declaration, which is just what needs to be passed to the function. in this case a filename, and the other stuff
    Last edited by Iamien; 10-03-2005 at 01:19 PM.

  3. #18
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    I actually tryed wav instead before you posted.
    Well, this code dont work for me.
    Code:
    //Many includes because I just copyed from a other program
    #include <iostream>
    #include <windows.h>
    #include <stdio.h>
    #include <conio.h>
    #include <usefull.h>
    #include <Mmsystem.h>
    
    using namespace std;
    
    int main(void)
    {
        bool success = PlaySound("test.wav", NULL, SND_ASYNC | SND_FILENAME);
        
        if(!success) {
            MessageBox(HWND_DESKTOP,"Could not find test.wav","",MB_OK);
            return 1;
        }
      
        cin.get();
    }

  4. #19
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Code that worked for me on Dev-C++ 4.9.9.2:
    Code:
    #include <windows.h>
    #include <mmsystem.h>
    
    int main()
    {
        PlaySound("test.wav",NULL,SND_ASYNC|SND_FILENAME);
        Sleep(1000);
        return 0;
    }
    But don't forget to link the Windows Multi-Media library. I also tried system("PAUSE"); in place of Sleep() and it worked. I just used Sleep so I wouldn't have to include another header. Change the value passed to Sleep depending on the length of your wave file, or just use system("PAUSE"), either way. Also, make sure the .wav file is a real .wav, don't just change the file type by renaming or whatever, if you're not sure make a .wav file by using Sound Recorder(including in all/most Windows versions).
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  5. #20
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    I coverted the mp3 to a wav...
    I got Dev-Cpp too, and I used the exact same code as you.
    But the damn song still dont play.
    Is it because I have "-lwinmm" on Tools > Compiler Options > "Add these commands to the linker command line" ???

    Or because the file is a full 4 min song?

  6. #21
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    I used the -lwinmm in the same spot as you, seeing as I told you to do it that way, and it worked. However my wave file was not 4 mins, it was more like 4 seconds. Just to make sure it's not something else weird, try a small wave file made with Sound Recorder, then repost if that worked or not.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  7. #22
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    Worked with a 7 second long file. =D
    But any idea of how I can use a whole song?

  8. #23
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    rofl
    Anyone here know what Async means?
    Asyncrohnos (sp) meaning that function returns right away, any continues playing, whats happening here is that you play your song, and return right away, so your program flow continues and exits because theres no more program to run..

    Try removing this flag, or perhaps refering to that link i gave above, find a new flag to put in it s place.

    The reason mine worked and yours didn't, was that i used the .net enviorment, which will create a basic empty window for me. didn't occur to me about the async before though :P.

    If you are curious as to how this asynchronos state is achieved, read up on multi threading, which would clarify things, and maybe give you some ideas for your games.

  9. #24
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    I tryed SNC_NODEFAULT and it works now

    But I got another question.
    Is it possible to actually build the song into the exe?
    So its no need for an extra music file?

    That was the actuall question...
    Quote Originally Posted by XunTric
    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
    Last edited by XunTric; 10-03-2005 at 03:34 PM.

  10. #25
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    @ Iamien:
    I just had to add this in, it's asynchronous, not asynchronos.

    Anyways, about playing music, I looked it up in my handy Windows Programming 5th edition by Charles Petzold. The only music playing it talked about is with .midi files, so maybe you would want to check that out. About building it in, I'm pretty sure it can be done, but not sure how, YET.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  11. #26
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    >>but not sure how, YET

    That means you're gonna find out and post? :P

  12. #27
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    It means We dont know but i tell you to go look up resource files =D

  13. #28
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    And it means that we/I will try to find out by researching it as well, when I have time(which is not right now because of my homework). But should be soon.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

Page 2 of 2 FirstFirst 12
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, 03:28 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  3. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 09:49 PM
  4. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 08:48 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21