Waking up WAV device

S

Scott Gifford

Hello,

I'm doing a notification beep from a device that's asleep (it's
receiving a network notification). To do this, I put the device into
unattended mode, request the "WAV1:" device, play the sound, then
release WAV1: and leave unattended mode.

This basically works, but the request for WAV1: seems to return before
the device is ready, and SystemSounds.Beep.Play() also returns before
the sound is done playing. To compensate for this, I use
Thread.Sleep() statements. This works, but seems error-prone. For
example, I imagine the time it takes to wake up the sound device
varies between handhelds, and the user's sytem beep could be longer
than my sleep (which could cut it off) or shoter (which is better, but
will still waste power).

I was wondering first if this is how it's supposed to work, or if I
might be doing something wrong? If so, is there was a way to request
a device synchronously, and a way to play a system sound
synchronously? Or maybe to receive a notification when these events
are complete?

Here is my code. I've modified it slightly to make it clearer, please
excuse any typoes. Some of the code is P/Invokes implemented in my
classes PowerPolicy and PowerHelper, implemented in the obvious ways.

PowerPolicy.PowerPolicyNotify(PowerPolicy.PPN_UNATTENDEDMODE, 1);
try
{
IntPtr pwrHandle = PowerHelper.SetPowerRequirement("WAV1:",
PowerHelper.CEDEVICE_POWER_STATE.D0,
PowerHelper.POWER_NAME | PowerHelper.POWER_FORCE,
null, 0);
if (pwrHandle == null)
throw new Exception("Error requesting WAV1 power on: " + Marshal.GetLastWin32Error());
try
{
// Give the device a second to wake up
System.Threading.Thread.Sleep(1000);

OpenNETCF.Media.SystemSounds.Beep.Play();
// Wait a few seconds for the sound to stop
// playing before powering off the device.
System.Threading.Thread.Sleep(5000);
}
finally
{
powerSound.Release();
}
}
finally
{
PowerPolicy.stopUnattendedMode();
}

Thanks for any help or advice!

----Scott.
 
S

Scott Gifford

Fabien said:
Hi Scott,

In CF 3.5, you have a new class SoundPlayer and you can play a load
and play a sound synchronously.
Check out this link:
http://msdn2.microsoft.com/en-us/library/system.media.soundplayer_members(VS.90).aspx

Thanks Fabian,

I'm working in CF 2.0 (though I have VS2008 and could switch), and it
looks like the OpenNETCF class "OpenNETCF.Media.SoundPlayer" does
about the same thing. I couldn't find a way to play a system sound
(like SystemSounds.Beep) with SoundPlayer, though. Maybe I should
just use a WAV file instead.

Thanks again for your help!

----Scott.
 
G

Guest

We've got to have PlaySound wrapped in there somewhere (I don't know
offhand, as it's been a while since i looked at the media stuff).
 
S

Scott Gifford

We've got to have PlaySound wrapped in there somewhere (I don't know
offhand, as it's been a while since i looked at the media stuff).

Thanks ctacke,

I didn't know that was the name of the function I was looking for. I
couldn't find it in OpenNetCF, but I can P/Invoke it, and it does just
what I need.

It seems that this function also waits for the WAV1: device to wake up
before starting the sound, so it solved both my problems at once.

Thanks!

-----Scott.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top