protected virtual void RaiseAudioChanged(AudioChangedEventArgs.Commands command, string audioFile, double?leftVolume = null, double?rightVolume = null) { if (this.silent) { return; } AudioChanged?.Invoke(this, new AudioChangedEventArgs(command, audioFile, leftVolume, rightVolume)); }
private void FetchLyric() { if (cts != null) { cts.Cancel(); return; } cts = new CancellationTokenSource(); status = "가사 받는 중..."; Lyric.Clear(); AudioChanged?.BeginInvoke(null, null, null, null); Task.Run(async() => { Lyric ret = null; var a = LyricSource.GetLyricsAsync(AudioInfo); foreach (var lyricTask in a) { cts.Token.ThrowIfCancellationRequested(); try { ret = await lyricTask; break; } catch { } } ret?.Insert(0, new LyricLine()); cts.Token.ThrowIfCancellationRequested(); Lyric = ret ?? throw new LyricNotFoundException(); }, cts.Token).ContinueWith(result => { cts = null; if (result.IsCanceled) { FetchLyric(); } else if (result.IsFaulted) { status = "가사 없음"; lyric.Clear(); } }); }