/// <summary> /// 非同期で音声ファイルを停止します。 /// </summary> private async Task _StopSoundAsync(SoundService sound) { if (sound == null) { return; } // Sound を停止する sound.Stop(); // 閉じる sound.Close(); await Task.Delay(100); }
private async void MainForm_FormClosed(object sender, FormClosedEventArgs e) { SoundService sound = null; if (_Setting != null) { sound = await _PlaySoundAsync(_Setting.ExitingSound, true); } _AimpObserver.Dispose(); if (_Setting != null) { await _StopSoundAsync(sound); } }
/// <summary> /// 非同期で音声ファイルを再生します。 /// </summary> private async Task <SoundService> _PlaySoundAsync(string filePath, bool isClosing) { SoundService sound = null; if (filePath == null) { return(null); } try { // ファイルを開く sound = SoundService.Open(filePath); // 音声を再生 (音声が指定されない場合は、例外発生) sound.Play(); // Legato-NowPlaying が終了される時 if (isClosing) { // 終了メッセージ new LegatoMessageBox("Legato-NowPlaying を終了します。", "れがーとなうぷれしゅーりょー", 1500); } await Task.Delay(1000); return(sound); } catch (FileNotFoundException) { sound?.Close(); MessageBox.Show( $"mp3 再生エラーが発生しました。\r\nファイルが見つかりません: {filePath}", "mp3 再生エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }