Commit ceaf9a32 authored by 潘栩锋's avatar 潘栩锋 🚴

修改bug 报警声 文件没有,会出错

parent c48adad7
......@@ -76,7 +76,7 @@
</Setter.Value>
</Setter>
</Style>
</StackPanel.Resources>
<Button Content="{Binding OKContent}" FontFamily="YouYuan" Click="button_ok_Click"/>
</StackPanel>
......
......@@ -21,7 +21,7 @@ namespace FLY.ControlLibrary
public partial class Window_WarningTip : Window, INotifyPropertyChanged
{
static Window_WarningTip Current = null;
static Action StopEvent = null;
static Action StopEvent = null;
static Action OKEvent = null;
static int WarningTipID = 0;
......@@ -45,6 +45,7 @@ namespace FLY.ControlLibrary
/// </summary>
public string OKContent { get; set; } = "确定";
public Window_WarningTip()
{
InitializeComponent();
......@@ -72,33 +73,40 @@ namespace FLY.ControlLibrary
/// <summary>
/// 关闭
/// </summary>
public static void Stop()
public static void Stop()
{
Current?.timer1_Tick(null,null);
Current?.timer1_Tick(null, null);
}
/// <summary>
/// 关闭
/// </summary>
/// <param name="id"></param>
public static void Stop(int id)
public static void Stop(int id)
{
if (WarningTipID == id)
Stop();
}
void stopMusic()
void stopMusic()
{
isRunning = false;
outputDevice?.Stop();
outputDevice.Dispose();
outputDevice?.Dispose();
outputDevice = null;
audioFile.Dispose();
audioFile?.Dispose();
audioFile = null;
}
void playMusic(string musicpath)
{
audioFile = new AudioFileReader(musicpath);
try
{
audioFile = new AudioFileReader(musicpath);
}
catch
{
//音乐无法启动
return;
}
outputDevice = new WaveOutEvent();
......@@ -116,7 +124,12 @@ namespace FLY.ControlLibrary
}
void Play(string musicpath)
{
if (audioFile == null)
if (musicpath == null)
{
//没有音乐,关闭
stopMusic();
}
else if (audioFile == null)
{
playMusic(musicpath);
}
......@@ -133,7 +146,7 @@ namespace FLY.ControlLibrary
timer.Stop();
}
else
else
{
timer.Interval = Duration;
timer.Start();
......@@ -146,7 +159,7 @@ namespace FLY.ControlLibrary
/// <param name="title">标题</param>
/// <param name="message">内容</param>
/// <returns>ID</returns>
public static int Show(string title, string message)
public static int Show(string title, string message)
{
return Show(title, message, TimeSpan.MaxValue);
}
......@@ -198,13 +211,13 @@ namespace FLY.ControlLibrary
/// <param name="okcontent">确定按键 显示字符串</param>
/// <param name="okhandler">确定事件 回调函数</param>
/// <returns>ID</returns>
public static int Show(string title, string message, TimeSpan duration, string musicpath, Action stophandler, string okcontent, Action okhandler)
public static int Show(string title, string message, TimeSpan duration, string musicpath, Action stophandler, string okcontent, Action okhandler)
{
if (Current == null)
{
Current = new Window_WarningTip();
}
Current.Title = title;
Current.Duration = duration;
......@@ -218,7 +231,7 @@ namespace FLY.ControlLibrary
Current.Play(musicpath);
WarningTipID++;
if (WarningTipID >= int.MaxValue-1)
if (WarningTipID >= int.MaxValue - 1)
WarningTipID = 0;
return WarningTipID;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment