Exemplo n.º 1
0
        private List <SrtRecord> GetFormattedSubtitles(Caption[] captions, int totalDuration)
        {
            List <SrtRecord> srtRecords = new List <SrtRecord>();

            System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");

            for (int i = 0; i < captions.Length - 1; ++i)
            {
                SrtRecord srtRecord = new SrtRecord
                {
                    FromTimeSpan = TimeSpan.FromSeconds(double.Parse(captions[i].DisplayTimeOffset, culture)),
                    ToTimeSpan   = TimeSpan.FromSeconds(double.Parse(captions[i + 1].DisplayTimeOffset, culture)),
                    Text         = (captions[i].Text)
                };
                srtRecords.Add(srtRecord);
            }

            SrtRecord finalSrtRecord = new SrtRecord
            {
                FromTimeSpan = TimeSpan.FromSeconds(Double.Parse(captions.Last().DisplayTimeOffset, culture)),
                ToTimeSpan   = TimeSpan.FromSeconds(Convert.ToDouble(totalDuration)),
                Text         = captions.Last().Text
            };

            srtRecords.Add(finalSrtRecord);
            return(srtRecords);
        }
        private List <SrtRecord> GetFormattedSubtitles(Caption[] captions, string totalDuration)
        {
            List <SrtRecord> srtRecords = new List <SrtRecord>();

            System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");

            for (int i = 0; i < captions.Length - 1; ++i)
            {
                SrtRecord srtRecord = new SrtRecord
                {
                    FromTimeSpan = TimeSpan.FromSeconds(double.Parse(captions[i].DisplayTimeOffset, culture)),
                    ToTimeSpan   = TimeSpan.FromSeconds(double.Parse(captions[i + 1].DisplayTimeOffset, culture)),
                    Text         = (captions[i].Text)
                };
                srtRecords.Add(srtRecord);
            }

            var toTimeSpan = IsoTimeToTimeSpanConverter.Instance.Convert(totalDuration, typeof(String), null, CultureInfo.CurrentCulture) ?? new TimeSpan();

            SrtRecord finalSrtRecord = new SrtRecord
            {
                FromTimeSpan = TimeSpan.FromSeconds(Double.Parse(captions.Last().DisplayTimeOffset, culture)),
                ToTimeSpan   = TimeSpan.Parse(toTimeSpan.ToString()), //TimeSpan.FromSeconds(Convert.ToDouble(totalDuration)),
                Text         = captions.Last().Text
            };

            srtRecords.Add(finalSrtRecord);
            return(srtRecords);
        }