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

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

parent c48adad7
...@@ -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();
...@@ -74,7 +75,7 @@ namespace FLY.ControlLibrary ...@@ -74,7 +75,7 @@ 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>
/// 关闭 /// 关闭
...@@ -90,15 +91,22 @@ namespace FLY.ControlLibrary ...@@ -90,15 +91,22 @@ namespace FLY.ControlLibrary
{ {
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)
{
try
{ {
audioFile = new AudioFileReader(musicpath); 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);
} }
...@@ -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