Stability fixes with streaming

This commit is contained in:
watsonb8
2020-02-05 18:44:48 -05:00
parent aae221801a
commit 89b928bd00
4 changed files with 52 additions and 34 deletions

View File

@ -110,32 +110,31 @@ namespace Aurora.Services.Server.Controllers
bool continueSync = true;
using (var scope = App.Container.BeginLifetimeScope())
{
IPlayer player = scope.Resolve<IPlayer>();
string currentId = player.CurrentMedia.Id;
MediaChangedEventHandler mediaChanged = (sender, e) =>
try
{
if (e.NewId != currentId)
IPlayer player = scope.Resolve<IPlayer>();
string currentId = player.CurrentMedia.Id;
while (continueSync)
{
continueSync = false;
float length = player.CurrentMediaLength;
Sync sync = new Sync()
{
TrackPosition = player.CurrentMediaPosition,
ServerTimeTicks = Utils.TimeUtils.GetNetworkTime().DateTime.Ticks
};
await responseStream.WriteAsync(sync);
Console.WriteLine("Sent Sync");
await Task.Delay(5000);
}
};
player.MediaChanged += mediaChanged;
while (continueSync)
{
float length = player.CurrentMediaLength;
Sync sync = new Sync()
{
TrackPosition = player.CurrentMediaPosition,
ServerTimeTicks = Utils.TimeUtils.GetNetworkTime().DateTime.Ticks
};
await responseStream.WriteAsync(sync);
Console.WriteLine("Sent Sync");
await Task.Delay(5000);
}
catch (Exception ex)
{
Console.WriteLine("Error sending sync: " + ex.Message);
}
}
}