Example #1
0
        private bool Read(string srtPath)
        {
            var lines = File.ReadAllLines(srtPath);

            for (int n = 0; n < lines.Length; ++n)
            {
                var line = lines[n];
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                // first line in section is the subtitle number (1, 2, 3 etc)...
                if (!int.TryParse(line, out var number))
                {
                    return(false);
                }

                if (n >= lines.Length - 1)
                {
                    return(false);
                }

                line = lines[++n];

                // second line is the start and end timing of the subtitle...
                if (!SubtitleTiming.TryParse(line, out var timing))
                {
                    return(false);
                }

                if (n >= lines.Length - 1)
                {
                    return(false);
                }

                line = lines[++n];

                var text = new List <string>();
                while (!string.IsNullOrEmpty(line) && n < lines.Length - 1)
                {
                    text.Add(line.Trim());
                    line = lines[++n];
                }

                var entry = new SubtitleEntry
                {
                    Number = number,
                    Timing = timing,
                    Text   = StripHtml(text)
                };

                _subtitles.Add(entry);
            }

            return(true);
        }
Example #2
0
        private void QueueNextSubtitle()
        {
            var videoPlaybackTime = DateTime.UtcNow - _videoStartTime;

            _currentSubtitle = _file?.GetNext();
            while (_currentSubtitle != null && _currentSubtitle.Timing.End < videoPlaybackTime)
            {
                _currentSubtitle = _file?.GetNext();
            }

            if (_currentSubtitle == null)
            {
                OnSubtitleEvent(SubtitleStatus.NotShowing, null);
            }
            else
            {
                ConfigureTimer(videoPlaybackTime);
            }
        }