2014-05-11 04:47:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2014-06-11 14:42:03 +00:00
|
|
|
|
using System.Threading;
|
2014-05-11 04:47:48 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.MediaEncoding.Subtitles
|
|
|
|
|
{
|
|
|
|
|
public class VttWriter : ISubtitleWriter
|
|
|
|
|
{
|
2014-06-11 14:42:03 +00:00
|
|
|
|
public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var writer = new StreamWriter(stream);
|
|
|
|
|
|
|
|
|
|
try
|
2014-05-11 06:29:44 +00:00
|
|
|
|
{
|
|
|
|
|
writer.WriteLine("WEBVTT");
|
|
|
|
|
writer.WriteLine(string.Empty);
|
|
|
|
|
foreach (var trackEvent in info.TrackEvents)
|
|
|
|
|
{
|
2014-06-11 14:42:03 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
2014-05-11 06:29:44 +00:00
|
|
|
|
writer.WriteLine(@"{0:hh\:mm\:ss\.fff} --> {1:hh\:mm\:ss\.fff}", TimeSpan.FromTicks(trackEvent.StartPositionTicks), TimeSpan.FromTicks(trackEvent.EndPositionTicks));
|
|
|
|
|
writer.WriteLine(trackEvent.Text);
|
|
|
|
|
writer.WriteLine(string.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-11 14:42:03 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
writer.Dispose();
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2014-05-11 04:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|