public SubtitleMonitorTask(int videoSeq, Language language, SubtitleType type, TimeSpan period, VSharpService service) : base(videoSeq, period, service) { Language = language; Type = type; Id = new SubtitleMonitorTaskId(videoSeq, language, type); Timer = new Timer(async(s) => { if (Checking) { return; } // Set flag to prevent overlapping checks Checking = true; try { VODInfo vodInfo = await Service.GetVODInfoAsync(VideoSeq); // Only continue if the VOD has caption data if (vodInfo.CaptionInfo == null) { return; } foreach (var details in vodInfo.CaptionInfo.Details) { if (details.Locale == Language.Value && details.Type.ToLower() == Type.Value) { SubtitleAvailable.Invoke(null, CreateSubtitleEventArgs(VideoSeq, details)); } } } catch (Exception e) { ExceptionThrown.Invoke(null, e); } finally { Checking = false; } }, null, Timeout.Infinite, Timeout.Infinite); }
private void SubtitleAvailableRepeater(object sender, SubtitlesAvailableEventArgs e) { UnregisterSubtitleMonitor(e.VideoSeq, e.Locale, e.Type); SubtitleAvailable.Invoke(sender, e); }