![]() |
|
Play wav sound on Pocket PC
By Vassili Philippov, August 23, 2001.
IntroductionThere are several functions on Pocket PC that can be used for playing sound in your program. These are: PlaySound, MessageBeep, waveOutWrite and other waveOut... functions.
What You Need
PlaySoundIt's easy to play sound using PlaySound function. Let's start with an example. The following code plays empty.wav files in \Windows folder. If your \Windows folder doesn't contain this file then copy any .wav file and rename it to empty.wav. PlaySound function can play .wav file from different sources. In the example above it plays it from a file. It can also play a file using data in memory and in application resources. This function can also be used for playing system sounds. There are two modes of playing sound synchronous and asynchronous. Use SND_SYNC and SND_ASYNC values in flag parameter to choose a necessary mode. Playing .wav files using PlaySoundExample: Playing .wav file you should remember that Pocket PC doesn't support relative file names. So you should always provide the full path to the file. Playing .wav resources using PlaySoundPlaying sound from a resource can be convenient if your application has a fixed number of sounds to play. Using resources instead of files allows you to avoid many .wav files that can be extremely helpful if you are going to create an application that consists of one executable file.
First of all you should create .wav resources. Create a custom resource:
enter WAVE resource type:
choose the resource name and file where the sound will be stored: Then copy necessary .wav file into testsound.wav and you could use this resource like: Play .wav data from memory using PlaySoundSometimes it's necessary to play sounds when the content of .wav file is stored in memory. I used to meet two situations: one when I received a file using network and another when I read a .wav file from compound document. The content of the .wav file should be located as one piece of memory. An example below reads the file into memory (assuming that the file size is less then 100Kb) and then plays sound from memory: ConclusionPlaySound function is suitable when your sound is in .wav format. You could add some .wav sounds to resources that will allow you to avoid additional .wav files in an application. Related resources:
DiscussDiscuss this article. Here you can write your comments and read comments of other developers. |
|||||||||||||||||||||