private static WebVTTDocument ParseDocument(StringReader reader, TimeSpan timeOffset)
        {
            var blockReader = new BlockDocumentReader(reader);
            if (!blockReader.ReadBlock().StartsWith(bodyIdentifier)) throw new Exception("Invalid WebVTT start identifier");

            var result = new WebVTTDocument();
            WebVTTCue previousCue = null;
            while (true)
            {
                var block = blockReader.ReadBlock();
                if (block == null) break;
                else if (!block.StartsWith(noteIdentifier)) // ignore comments
                {
                    // cue found
                    var cue = ParseCue(block, timeOffset);
                    if (previousCue != null && cue.Begin < previousCue.Begin) throw new Exception("Invalid WebVTT cue start time");
                    if (cue.End <= cue.Begin) throw new Exception("Invalid WebVTT cue end time");
                    result.Cues.Add(cue);
                    previousCue = cue;
                }
            }
            return result;
        }
示例#2
0
        private static WebVTTDocument ParseDocument(StringReader reader, TimeSpan timeOffset)
        {
            var blockReader = new BlockDocumentReader(reader);

            if (!blockReader.ReadBlock().StartsWith(bodyIdentifier))
            {
                throw new Exception("Invalid WebVTT start identifier");
            }

            var       result      = new WebVTTDocument();
            WebVTTCue previousCue = null;

            while (true)
            {
                var block = blockReader.ReadBlock();
                if (block == null)
                {
                    break;
                }
                else if (!block.StartsWith(noteIdentifier)) // ignore comments
                {
                    // cue found
                    var cue = ParseCue(block, timeOffset);
                    if (previousCue != null && cue.Begin < previousCue.Begin)
                    {
                        throw new Exception("Invalid WebVTT cue start time");
                    }
                    if (cue.End <= cue.Begin)
                    {
                        throw new Exception("Invalid WebVTT cue end time");
                    }
                    result.Cues.Add(cue);
                    previousCue = cue;
                }
            }
            return(result);
        }