本文整理汇总了C#中MediaPlayer.MakeDisposable方法的典型用法代码示例。如果您正苦于以下问题:C# MediaPlayer.MakeDisposable方法的具体用法?C# MediaPlayer.MakeDisposable怎么用?C# MediaPlayer.MakeDisposable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.MakeDisposable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AlertService
/// <summary>
/// Initializes a new instance of the <see cref="AlertService"/>.
/// </summary>
/// <param name="dumpDir">Temp files directory.</param>
public AlertService(string dumpDir)
{
if (dumpDir.IsEmpty())
throw new ArgumentNullException("dumpDir");
ThreadingHelper
.Thread(() =>
{
try
{
var player = new MediaPlayer();
var fileName = Path.Combine(dumpDir, "alert.mp3");
if (!File.Exists(fileName))
Properties.Resources.Alert.Save(fileName);
player.Open(new Uri(fileName, UriKind.RelativeOrAbsolute));
var logManager = ConfigManager.GetService<LogManager>();
using (var speech = new SpeechSynthesizer())
using (var client = new NotificationClient())
using (player.MakeDisposable(p => p.Close()))
{
while (!IsDisposed)
{
Tuple<AlertTypes, string, string, DateTime> alert;
if (!_alerts.TryDequeue(out alert))
break;
try
{
switch (alert.Item1)
{
case AlertTypes.Sound:
player.Play();
break;
case AlertTypes.Speech:
speech.Speak(alert.Item2);
break;
case AlertTypes.Popup:
GuiDispatcher.GlobalDispatcher.AddAction(() => new AlertPopupWindow
{
Title = alert.Item2,
Message = alert.Item3,
Time = alert.Item4
}.Show());
break;
case AlertTypes.Sms:
client.SendSms(alert.Item2);
break;
case AlertTypes.Email:
client.SendEmail(alert.Item2, alert.Item3);
break;
case AlertTypes.Log:
logManager.Application.AddWarningLog(() => LocalizedStrings.Str3033Params
.Put(alert.Item4, alert.Item2, Environment.NewLine + alert.Item3));
break;
default:
throw new ArgumentOutOfRangeException();
}
}
catch (Exception ex)
{
ex.LogError();
}
}
}
}
catch (Exception ex)
{
ex.LogError();
}
})
.Name("Alert thread")
.Launch();
}