From 89fc5aa11ade9343d29db679849c553ef6e0ce17 Mon Sep 17 00:00:00 2001 From: dkanada Date: Sun, 15 Mar 2020 00:00:55 +0900 Subject: [PATCH] Merge pull request #2582 from Bond-009/subs Fix subtitles (cherry picked from commit 6960f0af67d77210b75e2f54844538badeacbda6) Signed-off-by: Joshua M. Boniface --- .../Subtitles/SubtitleEncoder.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs index a4a7595d29..72db569744 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs @@ -183,11 +183,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles private async Task GetSubtitleStream(string path, MediaProtocol protocol, bool requiresCharset, CancellationToken cancellationToken) { - if (requiresCharset) + using (var stream = await GetStream(path, protocol, cancellationToken).ConfigureAwait(false)) { - using (var stream = await GetStream(path, protocol, cancellationToken).ConfigureAwait(false)) + if (requiresCharset) { var result = CharsetDetector.DetectFromStream(stream).Detected; + stream.Position = 0; if (result != null) { @@ -199,9 +200,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles return new MemoryStream(Encoding.UTF8.GetBytes(text)); } } - } - return File.OpenRead(path); + return stream; + } } private async Task GetReadableFile( @@ -745,6 +746,8 @@ namespace MediaBrowser.MediaEncoding.Subtitles { Url = path, CancellationToken = cancellationToken, + + // Needed for seeking BufferContent = true };