|
@@ -78,7 +78,6 @@ namespace FireDrill
|
|
|
// Bitmap to display
|
|
|
private WriteableBitmap _colorBitmap;
|
|
|
private SoundPlayer soundPlayer = new SoundPlayer();
|
|
|
- private Boolean isAudioPlaying = false;
|
|
|
|
|
|
public MainWindow()
|
|
|
{
|
|
@@ -87,6 +86,14 @@ namespace FireDrill
|
|
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
+ // 交互式控制
|
|
|
+ VideoPlayer.LoadedBehavior = MediaState.Manual;
|
|
|
+ // 添加元素加载完成事件 -- 自动开始播放
|
|
|
+ VideoPlayer.Loaded += new RoutedEventHandler(Media_Loaded);
|
|
|
+ // 添加媒体播放结束事件 -- 重新播放
|
|
|
+ VideoPlayer.MediaEnded += new RoutedEventHandler(Media_MediaEnded);
|
|
|
+ // 添加元素卸载完成事件 -- 停止播放
|
|
|
+ VideoPlayer.Unloaded += new RoutedEventHandler(Media_Unloaded);
|
|
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
|
string videoContent = Properties.Settings.Default.Video;
|
|
|
string audioContent = Properties.Settings.Default.Audio;
|
|
@@ -96,7 +103,8 @@ namespace FireDrill
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
+ // 绑定视频文件
|
|
|
+ VideoPlayer.Source = new Uri(videoContent);
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(audioContent))
|
|
|
{
|
|
@@ -117,6 +125,7 @@ namespace FireDrill
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ soundPlayer?.Stop();
|
|
|
if (_bodyFrameReader != null)
|
|
|
{
|
|
|
_bodyFrameReader.Dispose();
|
|
@@ -162,6 +171,8 @@ namespace FireDrill
|
|
|
dialog.ShowDialog();
|
|
|
if (dialog.DialogResult.Value)
|
|
|
{
|
|
|
+ VideoPlayer.Source = new Uri(Properties.Settings.Default.Video);
|
|
|
+ VideoPlayer.Play();
|
|
|
soundPlayer.SoundLocation = Properties.Settings.Default.Audio;
|
|
|
}
|
|
|
}
|
|
@@ -169,7 +180,7 @@ namespace FireDrill
|
|
|
private void FullScreen_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
ToolBar.Visibility = Visibility.Hidden;
|
|
|
- // ViewBox.Margin = new Thickness { Left = 0, Top = 0, Right = 0, Bottom = 0 };
|
|
|
+ ViewBox.Margin = new Thickness { Left = 0, Top = 0, Right = 0, Bottom = 0 };
|
|
|
Topmost = false;
|
|
|
WindowStyle = WindowStyle.None;
|
|
|
WindowState = WindowState.Maximized;
|
|
@@ -185,11 +196,11 @@ namespace FireDrill
|
|
|
new AboutWindow().ShowDialog();
|
|
|
}
|
|
|
|
|
|
- private void Music_Click(object sender, RoutedEventArgs e)
|
|
|
+ private void Music_Checked(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if (isAudioPlaying)
|
|
|
+ if (string.IsNullOrEmpty(soundPlayer.SoundLocation))
|
|
|
{
|
|
|
- soundPlayer.Stop();
|
|
|
+ MessageBox.Show("请先配置音频!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -198,7 +209,28 @@ namespace FireDrill
|
|
|
// 循环播放音频
|
|
|
soundPlayer.PlayLooping();
|
|
|
}
|
|
|
- isAudioPlaying = !isAudioPlaying;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Music_Unchecked(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ soundPlayer?.Stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void Media_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ (sender as MediaElement)?.Pause();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void Media_MediaEnded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ // MediaElement 需要先停止播放才能再开始播放,否则会停在最后一帧不动
|
|
|
+ (sender as MediaElement)?.Stop();
|
|
|
+ (sender as MediaElement)?.Play();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void Media_Unloaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ (sender as MediaElement)?.Stop();
|
|
|
}
|
|
|
}
|
|
|
}
|