本文整理汇总了C#中Nikse.SubtitleEdit.Core.TimeCode类的典型用法代码示例。如果您正苦于以下问题:C# TimeCode类的具体用法?C# TimeCode怎么用?C# TimeCode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TimeCode类属于Nikse.SubtitleEdit.Core命名空间,在下文中一共展示了TimeCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WritePts
public static void WritePts(this Stream stream, TimeCode timeCode)
{
//TODO: check max
var pts = (ulong)Math.Round(timeCode.TotalMilliseconds * 90.0);
var buffer = BitConverter.GetBytes((UInt64)pts);
stream.Write(buffer, 0, 5);
}
示例2: Paragraph
public Paragraph(string text, double startTotalMilliseconds, double endTotalMilliseconds)
{
StartTime = new TimeCode(startTotalMilliseconds);
EndTime = new TimeCode(endTotalMilliseconds);
Text = text;
ID = GenerateId();
}
示例3: TimeCodeAddTime5
public void TimeCodeAddTime5()
{
var tc = new TimeCode(1000);
tc.AddTime(0, 1, 0, 0);
Assert.AreEqual(tc.TotalMilliseconds, 60000 + 1000);
}
示例4: ToText
public override string ToText(Subtitle subtitle, string title)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("Title: " + title);
sb.AppendLine("Translator: No Author");
sb.AppendLine("Date: " + DateTime.Now.ToString("dd-MM-yyyy").Replace("-", ".")); // 25.08.2011
double milliseconds = 0;
if (subtitle.Paragraphs.Count > 0)
{
milliseconds = subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].EndTime.TotalMilliseconds;
}
TimeCode tc = new TimeCode(milliseconds);
sb.AppendLine(string.Format("Duration: {0:00}:{1:00}:{2:00}:{3:00}", tc.Hours, tc.Minutes, tc.Seconds, MillisecondsToFramesMaxFrameRate(tc.Milliseconds))); // 01:20:49:12
sb.AppendLine("Program start: 00:00:00:00");
sb.AppendLine("Title count: " + subtitle.Paragraphs.Count);
sb.AppendLine();
sb.AppendLine("#\tIn\tOut\tDuration");
sb.AppendLine();
int count = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
count++;
string text = HtmlUtil.RemoveHtmlTags(p.Text);
sb.AppendLine(string.Format("{13}\t{0:00}:{1:00}:{2:00}:{3:00}\t{4:00}:{5:00}:{6:00}:{7:00}\t{8:00}:{9:00}:{10:00}:{11:00}\r\n{12}" + Environment.NewLine, p.StartTime.Hours, p.StartTime.Minutes, p.StartTime.Seconds, MillisecondsToFramesMaxFrameRate(p.StartTime.Milliseconds), p.EndTime.Hours, p.EndTime.Minutes, p.EndTime.Seconds, MillisecondsToFramesMaxFrameRate(p.EndTime.Milliseconds), p.Duration.Hours, p.Duration.Minutes, p.Duration.Seconds, MillisecondsToFramesMaxFrameRate(p.Duration.Milliseconds), text, count));
}
return sb.ToString().Trim() + Environment.NewLine + Environment.NewLine + Environment.NewLine;
}
示例5: TimeCodeAddTime6
public void TimeCodeAddTime6()
{
var tc = new TimeCode(1000);
tc.AddTime(TimeSpan.FromMilliseconds(1000));
Assert.AreEqual(tc.TotalMilliseconds, 2000);
}
示例6: Paragraph
public Paragraph(TimeCode startTime, TimeCode endTime, string text)
{
StartTime = startTime;
EndTime = endTime;
Text = text;
ID = GenerateId();
}
示例7: TimeCodeAddTime7
public void TimeCodeAddTime7()
{
var tc = new TimeCode(1000);
tc.AddTime(1000.0);
Assert.AreEqual(tc.TotalMilliseconds, 2000);
}
示例8: SetCurrentPosition
public void SetCurrentPosition(double currentPositionInseconds, double durationInSeconds)
{
var pos = new TimeCode(currentPositionInseconds * 1000.0);
var dur = new TimeCode(durationInSeconds * 1000.0);
_labelPosition.StringValue = pos.ToShortDisplayString() + " / " + dur.ToShortDisplayString();
_positionSlider.DoubleValue = currentPositionInseconds / durationInSeconds * 100.0;
}
示例9: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
// 00:04:10:92 - 00:04:13:32 Raise Yourself To Help Mankind
// 00:04:27:92 - 00:04:30:92 الجهة المتولية للمسئولية الاجتماعية لشركتنا.
_errorCount = 0;
Paragraph lastParagraph = null;
foreach (string line in lines)
{
if (string.IsNullOrWhiteSpace(line))
{
continue;
}
bool success = false;
Match match = null;
if (line.Length > 26 && line[2] == ':')
match = Regex.Match(line);
if (match != null && match.Success)
{
string s = line.Substring(0, match.Length);
s = s.Replace(" - ", ":");
s = s.Replace(" ", string.Empty);
string[] parts = s.Split(':');
if (parts.Length == 8)
{
int hours = int.Parse(parts[0]);
int minutes = int.Parse(parts[1]);
int seconds = int.Parse(parts[2]);
int milliseconds = int.Parse(parts[3]) * 10;
var start = new TimeCode(hours, minutes, seconds, milliseconds);
hours = int.Parse(parts[4]);
minutes = int.Parse(parts[5]);
seconds = int.Parse(parts[6]);
milliseconds = int.Parse(parts[7]) * 10;
var end = new TimeCode(hours, minutes, seconds, milliseconds);
string text = line.Substring(match.Length).TrimStart();
text = text.Replace("|", Environment.NewLine);
lastParagraph = new Paragraph(start, end, text);
subtitle.Paragraphs.Add(lastParagraph);
success = true;
}
}
else if (lastParagraph != null && Utilities.GetNumberOfLines(lastParagraph.Text) < 5)
{
lastParagraph.Text += Environment.NewLine + line.Trim();
success = true;
}
if (!success)
_errorCount++;
}
subtitle.Renumber();
}
示例10: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
var paragraph = new Paragraph();
ExpectingLine expecting = ExpectingLine.TimeStart;
_errorCount = 0;
subtitle.Paragraphs.Clear();
foreach (string line in lines)
{
if (line.StartsWith('[') && regexTimeCode.IsMatch(line))
{
string[] parts = line.Split(new[] { ':', ']', '[', ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 3)
{
try
{
int startHours = int.Parse(parts[0]);
int startMinutes = int.Parse(parts[1]);
int startSeconds = int.Parse(parts[2]);
var tc = new TimeCode(startHours, startMinutes, startSeconds, 0);
if (expecting == ExpectingLine.TimeStart)
{
paragraph = new Paragraph();
paragraph.StartTime = tc;
expecting = ExpectingLine.Text;
}
else if (expecting == ExpectingLine.TimeEnd)
{
paragraph.EndTime = tc;
expecting = ExpectingLine.TimeStart;
subtitle.Paragraphs.Add(paragraph);
paragraph = new Paragraph();
}
}
catch
{
_errorCount++;
expecting = ExpectingLine.TimeStart;
}
}
}
else
{
if (expecting == ExpectingLine.Text)
{
if (line.Length > 0)
{
string text = line.Replace("|", Environment.NewLine);
paragraph.Text = text;
expecting = ExpectingLine.TimeEnd;
}
}
}
}
subtitle.Renumber();
}
示例11: TimeCodeDaysTest
public void TimeCodeDaysTest()
{
var tc = new TimeCode(24 * 3, 0, 0, 0)
{
Hours = 0,
Minutes = 0,
Seconds = 0,
Milliseconds = 0,
};
Assert.IsTrue(tc.TotalMilliseconds > 0);
}
示例12: Paragraph
public Paragraph(Paragraph paragraph, bool generateNewId = true)
{
Number = paragraph.Number;
Text = paragraph.Text;
StartTime = new TimeCode(paragraph.StartTime.TotalMilliseconds);
EndTime = new TimeCode(paragraph.EndTime.TotalMilliseconds);
StartFrame = paragraph.StartFrame;
EndFrame = paragraph.EndFrame;
Forced = paragraph.Forced;
Extra = paragraph.Extra;
IsComment = paragraph.IsComment;
Actor = paragraph.Actor;
Effect = paragraph.Effect;
Layer = paragraph.Layer;
ID = generateNewId ? GenerateId() : paragraph.ID;
Language = paragraph.Language;
Style = paragraph.Style;
NewSection = paragraph.NewSection;
}
示例13: GetTimeCode
public static string GetTimeCode(TimeCode timeCode, string template)
{
var templateTrimmed = template.Trim();
if (templateTrimmed == "ss")
template = template.Replace("ss", string.Format("{0:00}", timeCode.TotalSeconds));
if (templateTrimmed == "s")
template = template.Replace("s", string.Format("{0}", timeCode.TotalSeconds));
if (templateTrimmed == "zzz")
template = template.Replace("zzz", string.Format("{0:000}", timeCode.TotalMilliseconds));
if (templateTrimmed == "z")
template = template.Replace("z", string.Format("{0}", timeCode.TotalMilliseconds));
if (templateTrimmed == "ff")
template = template.Replace("ff", string.Format("{0}", SubtitleFormat.MillisecondsToFrames(timeCode.TotalMilliseconds)));
if (template.StartsWith("ssssssss", StringComparison.Ordinal))
template = template.Replace("ssssssss", string.Format("{0:00000000}", timeCode.TotalSeconds));
if (template.StartsWith("sssssss", StringComparison.Ordinal))
template = template.Replace("sssssss", string.Format("{0:0000000}", timeCode.TotalSeconds));
if (template.StartsWith("ssssss", StringComparison.Ordinal))
template = template.Replace("ssssss", string.Format("{0:000000}", timeCode.TotalSeconds));
if (template.StartsWith("sssss", StringComparison.Ordinal))
template = template.Replace("sssss", string.Format("{0:00000}", timeCode.TotalSeconds));
if (template.StartsWith("ssss", StringComparison.Ordinal))
template = template.Replace("ssss", string.Format("{0:0000}", timeCode.TotalSeconds));
if (template.StartsWith("sss", StringComparison.Ordinal))
template = template.Replace("sss", string.Format("{0:000}", timeCode.TotalSeconds));
if (template.StartsWith("ss", StringComparison.Ordinal))
template = template.Replace("ss", string.Format("{0:00}", timeCode.TotalSeconds));
if (template.StartsWith("zzzzzzzz", StringComparison.Ordinal))
template = template.Replace("zzzzzzzz", string.Format("{0:00000000}", timeCode.TotalMilliseconds));
if (template.StartsWith("zzzzzzz", StringComparison.Ordinal))
template = template.Replace("zzzzzzz", string.Format("{0:0000000}", timeCode.TotalMilliseconds));
if (template.StartsWith("zzzzzz", StringComparison.Ordinal))
template = template.Replace("zzzzzz", string.Format("{0:000000}", timeCode.TotalMilliseconds));
if (template.StartsWith("zzzzz", StringComparison.Ordinal))
template = template.Replace("zzzzz", string.Format("{0:00000}", timeCode.TotalMilliseconds));
if (template.StartsWith("zzzz", StringComparison.Ordinal))
template = template.Replace("zzzz", string.Format("{0:0000}", timeCode.TotalMilliseconds));
if (template.StartsWith("zzz", StringComparison.Ordinal))
template = template.Replace("zzz", string.Format("{0:000}", timeCode.TotalMilliseconds));
template = template.Replace("hh", string.Format("{0:00}", timeCode.Hours));
template = template.Replace("h", string.Format("{0}", timeCode.Hours));
template = template.Replace("mm", string.Format("{0:00}", timeCode.Minutes));
template = template.Replace("m", string.Format("{0}", timeCode.Minutes));
template = template.Replace("ss", string.Format("{0:00}", timeCode.Seconds));
template = template.Replace("s", string.Format("{0}", timeCode.Seconds));
template = template.Replace("zzz", string.Format("{0:000}", timeCode.Milliseconds));
template = template.Replace("zz", string.Format("{0:00}", Math.Round(timeCode.Milliseconds / 10.0)));
template = template.Replace("z", string.Format("{0:0}", Math.Round(timeCode.Milliseconds / 100.0)));
template = template.Replace("ff", string.Format("{0:00}", SubtitleFormat.MillisecondsToFramesMaxFrameRate(timeCode.Milliseconds)));
template = template.Replace("f", string.Format("{0}", SubtitleFormat.MillisecondsToFramesMaxFrameRate(timeCode.Milliseconds)));
return template;
}
示例14: ConvertToTimeString
private string ConvertToTimeString(TimeCode time)
{
return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", time.Hours, time.Minutes, time.Seconds, DCinemaSmpte2010.MsToFramesMaxFrameRate(time.Milliseconds, frameRate));
}
示例15: EncodeTimeCode
private static string EncodeTimeCode(TimeCode time)
{
return string.Format("{0}:{1:00}", time.Hours * 60 + time.Minutes, time.Seconds);
}