Esempio n. 1
0
        private static TtElement BuildDocument(XDocument xml, TimeSpan timeOffset, TimeSpan defaultEndTime)
        {
            TtElement parsetree = null;

            try
            {
                parsetree = (TtElement)TimedTextElementBase.Parse(xml.Root);
            }
            catch (TimedTextException) { }

            if (parsetree == null)
            {
                throw new TimedTextException("No Parse tree returned");
            }
            if (!parsetree.Valid())
            {
                throw new TimedTextException("Document is Well formed XML, but invalid Timed Text");
            }

            var startTime = new TimeCode(timeOffset, TimeExpression.CurrentSmpteFrameRate);
            var endTime   = new TimeCode(defaultEndTime, TimeExpression.CurrentSmpteFrameRate);

            parsetree.ComputeTimeIntervals(TimeContainer.Par, startTime, endTime);

            return(parsetree);
        }
Esempio n. 2
0
 public IEnumerable <CaptionRegion> ParseMarkerCollection(XDocument markerXml, TimeSpan timeOffset, TimeSpan defaultEndTime)
 {
     //try
     {
         TtElement document = BuildDocument(markerXml, timeOffset, defaultEndTime);
         return(BuildRegions(document));
     }
     //catch (Exception ex)
     //{
     //    throw new ArgumentException("TimedTextMarkerParser.ParseMarkerCollection received invalid input.", ex);
     //}
 }
Esempio n. 3
0
        private static IEnumerable <CaptionRegion> BuildRegions(TtElement document)
        {
            var regionElementsHash = document.Head != null
                                    ? document.Head.Children.Where(i => i is LayoutElement)
                                     .SelectMany(i => i.Children)
                                     .Cast <RegionElement>()
                                     .ToDictionary(i => i.Id, i => i)
                                    : new Dictionary <string, RegionElement>();

            var captionRegionsHash = regionElementsHash.Values
                                     .Select(MapToCaptionRegion)
                                     .ToDictionary(i => i.Id, i => i);

            if (document.Body != null)
            {
                BuildCaptions(document.Body, regionElementsHash, captionRegionsHash);
            }

            return(captionRegionsHash.Values.ToList());
        }