mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-19 20:54:20 +01:00
added live channel playback
This commit is contained in:
32
MediaBrowser.Api/Playback/EndlessStreamCopy.cs
Normal file
32
MediaBrowser.Api/Playback/EndlessStreamCopy.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Api.Playback
|
||||
{
|
||||
public class EndlessStreamCopy
|
||||
{
|
||||
public async Task CopyStream(Stream source, Stream target, CancellationToken cancellationToken)
|
||||
{
|
||||
long position = 0;
|
||||
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
await source.CopyToAsync(target, 81920, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var fsPosition = source.Position;
|
||||
|
||||
var bytesRead = fsPosition - position;
|
||||
|
||||
//Logger.Debug("Streamed {0} bytes from file {1}", bytesRead, path);
|
||||
|
||||
if (bytesRead == 0)
|
||||
{
|
||||
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
position = fsPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user