fix live stream
This commit is contained in:
parent
d721c92bba
commit
1591b16e00
|
@ -19,6 +19,7 @@ using System.Threading.Tasks;
|
|||
using CommonIO;
|
||||
using MediaBrowser.Api.Playback.Progressive;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Server.Implementations.LiveTv.EmbyTV;
|
||||
|
||||
namespace MediaBrowser.Api.LiveTv
|
||||
{
|
||||
|
@ -674,8 +675,6 @@ namespace MediaBrowser.Api.LiveTv
|
|||
{
|
||||
public string Id { get; set; }
|
||||
public string Container { get; set; }
|
||||
public long T { get; set; }
|
||||
public long S { get; set; }
|
||||
}
|
||||
|
||||
public class LiveTvService : BaseApiService
|
||||
|
@ -699,45 +698,18 @@ namespace MediaBrowser.Api.LiveTv
|
|||
_fileSystem = fileSystem;
|
||||
}
|
||||
|
||||
public object Get(GetLiveStreamFile request)
|
||||
public async Task<object> Get(GetLiveStreamFile request)
|
||||
{
|
||||
var filePath = Path.Combine(_config.ApplicationPaths.TranscodingTempPath, request.Id + ".ts");
|
||||
|
||||
var directStreamProvider = (await EmbyTV.Current.GetLiveStream(request.Id).ConfigureAwait(false)) as IDirectStreamProvider;
|
||||
var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
outputHeaders["Content-Type"] = MediaBrowser.Model.Net.MimeTypes.GetMimeType(filePath);
|
||||
// TODO: Don't hardcode this
|
||||
outputHeaders["Content-Type"] = Model.Net.MimeTypes.GetMimeType("file.ts");
|
||||
|
||||
long startPosition = 0;
|
||||
|
||||
if (request.T > 0)
|
||||
var streamSource = new ProgressiveFileCopier(directStreamProvider, outputHeaders, null, Logger, CancellationToken.None)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
var totalTicks = now.Ticks - request.S;
|
||||
|
||||
if (totalTicks > 0)
|
||||
{
|
||||
double requestedOffset = request.T;
|
||||
requestedOffset = Math.Max(0, requestedOffset - TimeSpan.FromSeconds(10).Ticks);
|
||||
|
||||
var pct = requestedOffset / totalTicks;
|
||||
|
||||
Logger.Info("Live stream offset pct {0}", pct);
|
||||
|
||||
var bytes = new FileInfo(filePath).Length;
|
||||
Logger.Info("Live stream total bytes {0}", bytes);
|
||||
startPosition = Convert.ToInt64(pct * bytes);
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Info("Live stream starting byte position {0}", startPosition);
|
||||
|
||||
var streamSource = new ProgressiveFileCopier(_fileSystem, filePath, outputHeaders, null, Logger, CancellationToken.None)
|
||||
{
|
||||
AllowEndOfFile = false,
|
||||
StartPosition = startPosition
|
||||
AllowEndOfFile = false
|
||||
};
|
||||
|
||||
return ResultFactory.GetAsyncStreamWriter(streamSource);
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ namespace MediaBrowser.Api
|
|||
config.EnableLocalizedGuids = true;
|
||||
config.EnableStandaloneMusicKeys = true;
|
||||
config.EnableCaseSensitiveItemIds = true;
|
||||
//config.EnableFolderView = true;
|
||||
config.EnableFolderView = true;
|
||||
config.SchemaVersion = 109;
|
||||
config.EnableSimpleArtistDetection = true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user