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
        internal static bool UnitTests()
        {
            #region string preamble
            string preamble = @"<tt xml:lang =''
                   ttp:profile='http://www.w3.org/2006/10/ttaf1#profile-dfxp'
                   xmlns='http://www.w3.org/2006/10/ttaf1'
                   xmlns:ttm='http://www.w3.org/2006/10/ttaf1#metadata'
                   xmlns:ttp='http://www.w3.org/2006/10/ttaf1#parameter'
                   xmlns:tts='http://www.w3.org/2006/10/ttaf1#style' >
                 <head>
                       <ttm:title>Unit test</ttm:title>
                </head>
            ";
            #endregion

            XElement ttData1 = XElement.Parse(preamble + @"
                  <body timeContainer ='par' >
                        <div timeContainer ='seq' end='5s'>
                            <p  dur='2s'>One<span begin='0.5s' dur='1s' > and a bit</span></p>
                            <p  dur='2s'>Two</p>
                        </div>
                         <div timeContainer ='seq' dur='5s'>
                            <p  begin='0.1s' dur='2s'>One</p>
                            <p  dur='2s'>Two</p>
                        </div>
               </body>
            </tt>
            ");

            TimedTextElementBase tt1 = TimedTextElementBase.Parse(ttData1);
            bool     pass            = tt1.Valid();
            TimeCode startTime       = new TimeCode("00:00:00:00", TimeExpression.CurrentSmpteFrameRate);
            TimeCode endTime         = new TimeCode("01:00:00:00", TimeExpression.CurrentSmpteFrameRate);

            tt1.ComputeTimeIntervals(TimeContainer.Par, startTime, endTime);
            ReadOnlyCollection <TimeCode> ev = tt1.Events;

            // some basic tests, try to come up with some more devilish ones.
            pass &= ev.Count == 10;

            return(pass);
        }