Solved

Embedding sound files

Posted on 1998-11-07
9
163 Views
Last Modified: 2013-11-20
How could I embed a sound file (preferably midi) into an application so that it runs when a game is being played (and for a few extra points, how can I add an option (perhaps in a drop-menu) to turn the sound off?)
0
Comment
Question by:Mephisto
  • 5
  • 3
9 Comments
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1324336
Well, to add a file into an application, do this:

1) Select the "Resources" tab on the window in the main area of Developer Studio.

2) Right click on the name of your project.  This brings up a popup menu.

3) Select "Insert..."

4) Click the custom button.

5) Name the resource something like "Midi"

6) Right click on the "IDR_MIDI1" resource.

7) Click import.

8) Select the name of the midi file you want to bring into your project.

9) Voila! Now you have a midi file embedded in the EXE (no external file required).

Now, if you don't need a separate file embedded in the EXE (i.e. if you are okay with distributing external files), then your job is much easier.

You can simply use the PlaySound function to play a sound file.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1324337
Here is an example as to how to use the PlaySound function:

PlaySound ("C:\\yourdir\\yoursound.mid", NULL, SND_ASYNC | SND_FILENAME);

To stop the sound, use:

PlaySound (NULL, NULL, SND_PURGE);

0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1324338
If you have any further questions regarding this, please don't hesitate to ask.  Thanks!
0
 

Author Comment

by:Mephisto
ID: 1324339
Where can I place a call to the PlaySound function?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Mephisto
ID: 1324340
And if I do embed the file into the EXE, how can I call a function to play the embedded soundfile?
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1324341
You _would_ use the SND_MEMORY or SND_RESOURCE flgs.  But the problem is that thresher_shark's answer is all wet: PlaySound() doesn't work on MIDI files (or data); only on WAV files (or data).

B ekiM


0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1324342
Hence the "comment" ... mikeblas is correct, after some research I discovered you can't use the PlaySound function.  You can use a great class that I got of the internet though, go to:

http://www.codeguru.com/misc/midi.shtml

which has an excellent class for playing MIDI files from the resource.  PlaySound only works with WAVE files :-(

If you have any other questions, please feel free to ask.  Thanks!
0
 

Author Comment

by:Mephisto
ID: 1324343
Thank you very much....   the midi class is extremely helpful..   throw something into an answer if you want the points for it.. every bit of the original question has been answered or I figured out on my own.....
0
 
LVL 6

Accepted Solution

by:
thresher_shark earned 50 total points
ID: 1324344
Okay, I am glad everything has worked out for you.  I just found the class yesterday, and I too have found it to work very well.  Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 67
ORA-01403: no data found 43 83
either24  challenge 19 84
tripleUp challenge 7 67
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now