「aygshell.dll」で p/invoke を使用して Windows Mobile 6 の電話サウンド プロファイルにアクセスできましたが、Windows Phone 7 は次のコードをサポートしていません。これを回避する方法はありますか?アプリで電話をサイレント モードまたはバイブレーション モードに設定できるようにしたいと考えています。
/*The following code works perfectly well with windows moblile 6.0 but fails for
windows phone 7 at runtime. */
public enum SND_SOUNDTYPE
{
On,
File,
Vibrate,
None
}
private enum SND_EVENT
{
All,
RingLine1,
RingLine2,
KnownCallerLine1,
RoamingLine1,
RingVoip
}
//Marshals
[StructLayout(LayoutKind.Sequential)]
private struct SNDFILEINFO
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szPathName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
public SND_SOUNDTYPE sstType;
}
//p/invoke
[DllImport("aygshell.dll", SetLastError = true)]
private static extern uint SndSetSound(SND_EVENT seSoundEvent, ref SNDFILEINFO pSoundFileInfo, bool fSuppressUI);
[DllImport("aygshell.dll", SetLastError = true)]
private static extern uint SndGetSound(SND_EVENT seSoundEvent, ref SNDFILEINFO pSoundFileInfo);
//method to set ringer on
private static void SetProfileNormal()
{
SNDFILEINFO soundFileInfo = new SNDFILEINFO();
soundFileInfo.sstType = SND_SOUNDTYPE.On;
SndSetSound(SND_EVENT.All, ref soundFileInfo, true);
}
//method to set ringer to vibrate
private static void SetProfileVibrate()
{
SNDFILEINFO soundFileInfo = new SNDFILEINFO();
soundFileInfo.sstType = SND_SOUNDTYPE.Vibrate;
SndSetSound(SND_EVENT.All, ref soundFileInfo, true);
}
//method to set ringer off - silent mode
private static void SetProfileMuted()
{
SNDFILEINFO soundFileInfo = new SNDFILEINFO();
soundFileInfo.sstType = SND_SOUNDTYPE.None;
SndSetSound(SND_EVENT.All, ref soundFileInfo, true);
}
//method to check if phone is in vibrate mode
private bool IsInVibrateMode()
{
SNDFILEINFO info = new SNDFILEINFO();
SndGetSound(SND_EVENT.All, ref info);
return (info.sstType == SND_SOUNDTYPE.Vibrate);
}
//method to check if phone is in silent mode
private bool IsMuted()
{
SNDFILEINFO info = new SNDFILEINFO();
SndGetSound(SND_EVENT.All, ref info);
return (info.sstType == SND_SOUNDTYPE.None);
}