本文整理汇总了C#中Subtitle.RemoveParagraphsByIndices方法的典型用法代码示例。如果您正苦于以下问题:C# Subtitle.RemoveParagraphsByIndices方法的具体用法?C# Subtitle.RemoveParagraphsByIndices怎么用?C# Subtitle.RemoveParagraphsByIndices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subtitle
的用法示例。
在下文中一共展示了Subtitle.RemoveParagraphsByIndices方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
subtitle.Paragraphs.Clear();
subtitle.Header = null;
byte[] buffer = FileUtil.ReadAllBytesShared(fileName);
int i = 128;
Paragraph last = null;
while (i < buffer.Length - 20)
{
if (buffer[i] == 0x0b)
{
string timeCode = Encoding.ASCII.GetString(buffer, i + 1, 11);
if (timeCode != "00:00:00:00" && RegexTimeCodes.IsMatch(timeCode))
{
var p = new Paragraph { StartTime = DecodeTimeCode(timeCode.Split(':')) };
bool italic = buffer[i + 22] == 3; // 3=italic, 1=normal
int textStart = i + 25; // text starts 25 chars after time code
int textLength = 0;
while (textStart + textLength < buffer.Length && buffer[textStart + textLength] != 0)
{
textLength++;
}
if (textLength > 0)
{
p.Text = Encoding.GetEncoding(1252).GetString(buffer, textStart, textLength);
int rtIndex = p.Text.IndexOf("{\\rtf1", StringComparison.Ordinal);
if (rtIndex >= 0 && rtIndex < 10)
{
p.Text = p.Text.Substring(rtIndex).FromRtf();
}
else if (italic)
{
p.Text = "<i>" + p.Text + "</i>";
}
}
else
{
p.Text = string.Empty;
}
last = p;
subtitle.Paragraphs.Add(p);
}
}
i++;
}
if (last != null)
last.EndTime.TotalMilliseconds = last.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(last.Text);
for (i = 0; i < subtitle.Paragraphs.Count - 1; i++)
{
subtitle.Paragraphs[i].EndTime.TotalMilliseconds = subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds;
}
for (i = subtitle.Paragraphs.Count - 1; i >= 0; i--)
{
if (string.IsNullOrEmpty(subtitle.Paragraphs[i].Text))
subtitle.Paragraphs.RemoveAt(i);
}
var deletes = new List<int>();
for (i = 0; i < subtitle.Paragraphs.Count - 1; i++)
{
if (subtitle.Paragraphs[i].StartTime.TotalMilliseconds == subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds)
{
subtitle.Paragraphs[i].Text += Environment.NewLine + subtitle.Paragraphs[i + 1].Text;
subtitle.Paragraphs[i].EndTime = subtitle.Paragraphs[i + 1].EndTime;
deletes.Add(i + 1);
}
}
subtitle.RemoveParagraphsByIndices(deletes);
for (i = 0; i < subtitle.Paragraphs.Count - 1; i++)
{
if (subtitle.Paragraphs[i].StartTime.TotalMilliseconds == subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds)
{
}
else if (subtitle.Paragraphs[i].EndTime.TotalMilliseconds == subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds)
{
subtitle.Paragraphs[i].EndTime.TotalMilliseconds = subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds - 1;
}
}
subtitle.Renumber();
// adjust all times
if (buffer.Length > 1364)
{
try
{
string adjust = Encoding.GetEncoding(1252).GetString(buffer, 1354, 11); // 00:59:59:28
TimeCode tc = DecodeTimeCode(adjust.Split(':'));
if (tc.TotalMilliseconds > 0)
subtitle.AddTimeToAllParagraphs(TimeSpan.FromMilliseconds(-tc.TotalMilliseconds));
}
catch
{
}
}
}