playing sound from large interval timer

V

Vince Koser

I'm using OPENETCF large interval timer to wake up my app and do some operations. It works great except now I'm trying to add some alerts if new data was found during the event. I can trigger vibrations and it works great but using a pinvoke on WCE_PlaySound or using the multimedia PlaySync() in opennetcf will only play sounds reliably if the phone is awake and the screen is on.

If its in suspend mode the sound is unreliable and seems to only play if it happens to try and play during the same interval that my regular imap mail check is happening.

any ideas?

thanks
 
C

Chris Tacke, eMVP

I'm a little confused - so if the LIT wakes the device and you try to
PlaySound you're saying that fails, but if the device was already awake when
the timer fires, then it plays correctly?


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
S

Scott Gifford

Vince said:
I'm using OPENETCF large interval timer to wake up my app and do
some operations. It works great except now I'm trying to add some
alerts if new data was found during the event. I can trigger
vibrations and it works great but using a pinvoke on WCE_PlaySound
or using the multimedia PlaySync() in opennetcf will only play
sounds reliably if the phone is awake and the screen is on.

If its in suspend mode the sound is unreliable and seems to only
play if it happens to try and play during the same interval that my
regular imap mail check is happening.

I had a very similar problem. You need to ask the device to stay
awake, wake up the WAV: device, then wait a second or so for it to do
it; when you are done release the WAV device and tell the device it
can go back to sleep. You'll want to P/Invoke PowerPolicyNotify,
SetPowerRequirement, and ReleasePowerRequirement to do this. I used
code similar to this (sorry, I'm cut and pasting from a few sources,
so there might be errors. Also some of this code is probably taken
from various blogs, but I forgot to keep track of which ones).

public class DevicePower
{
public const UInt32 POWER_FORCE = 4096;
public const UInt32 POWER_NAME = 1;

public enum CEDEVICE_POWER_STATE
{
PwrDeviceUnspecified = -1,
D0 = 0,
D1,
D2,
D3,
D4,
PwrDeviceMaximum
};

[DllImport("coredll", SetLastError = true)]
extern public static IntPtr
SetPowerRequirement([MarshalAs(UnmanagedType.LPWStr)] string pvName,
CEDEVICE_POWER_STATE DeviceState,
UInt32 DeviceFlags,
[MarshalAs(UnmanagedType.LPWStr)] string pvSystemState,
UInt32 StateFlags);

[DllImport("coredll", SetLastError = true)]
extern public static UInt32 ReleasePowerRequirement(IntPtr handle);

public const int PPN_REEVALUATESTATE = 0x0001;
public const int PPN_POWERCHANGE = 0x0002;
public const int PPN_UNATTENDEDMODE = 0x0003;
public const int PPN_SUSPENDKEYPRESSED = 0x0004;
public const int PPN_POWERBUTTONPRESSED = 0x0004;
public const int PPN_SUSPENDKEYRELEASED = 0x0005;
public const int PPN_APPBUTTONPRESSED = 0x0006;
[DllImport("coredll")]
public extern static bool PowerPolicyNotify(int dwMessage, int
dwData);
}

then call it like this:

IntPtr wavHandle = IntPtr.Zero;
try
{
// Probably you should check the return code
PowerHelper.PowerPolicyNotify(PowerPolicy.PPN_UNATTENDEDMODE, 1);
wavHandle = PowerHelper.SetPowerRequirement("WAV1:",
PowerHelper.CEDEVICE_POWER_STATE.D0,
PowerHelper.POWER_NAME | PowerHelper.POWER_FORCE, null, 0);
if (wavHandle == IntPtr.Zero)
{
throw new System.ComponentModel.Win32Exception();
}

// May not be necessary?
Thread.Sleep(1000);

// Now play the sound here
}
finally
{
if (wavHandle != IntPtr.Zero)
{
// Maybe should check error here
ReleasePowerRequirement(wavHandle);
}
// Maybe should check error here
PowerHelper.PowerPolicyNotify(PowerPolicy.PPN_UNATTENDEDMODE, 0);
}

Hope this helps!

-----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