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

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

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