2019-11-11 20:10:08 +00:00
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Aurora.Proto.Sync;
|
|
|
|
using Aurora.Proto.General;
|
2020-02-01 01:41:45 +00:00
|
|
|
using Aurora.Services.Player;
|
|
|
|
using Aurora;
|
|
|
|
using Autofac;
|
2019-11-11 20:10:08 +00:00
|
|
|
|
|
|
|
namespace Aurora.RemoteImpl
|
|
|
|
{
|
|
|
|
public class RemoteSyncServiceImpl : RemoteSyncService.RemoteSyncServiceBase
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// RPC for getting a stream of media syncs
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
/// <param name="responseStream"></param>
|
|
|
|
/// <param name="context"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public override async Task GetMediaSync(Empty request,
|
|
|
|
Grpc.Core.IServerStreamWriter<Sync> responseStream,
|
|
|
|
Grpc.Core.ServerCallContext context)
|
|
|
|
{
|
2020-02-01 01:41:45 +00:00
|
|
|
using (var scope = App.Container.BeginLifetimeScope())
|
2019-11-11 20:10:08 +00:00
|
|
|
{
|
2020-02-01 01:41:45 +00:00
|
|
|
IPlayer player = scope.Resolve<IPlayer>();
|
|
|
|
bool continueSync = true;
|
|
|
|
string currentId = player.CurrentMedia.Id;
|
|
|
|
MediaChangedEventHandler mediaChanged = (sender, e) =>
|
2019-11-13 01:09:45 +00:00
|
|
|
{
|
2020-02-01 01:41:45 +00:00
|
|
|
if (e.NewId != currentId)
|
|
|
|
{
|
|
|
|
continueSync = false;
|
|
|
|
}
|
|
|
|
};
|
2019-11-11 20:10:08 +00:00
|
|
|
|
2020-02-01 01:41:45 +00:00
|
|
|
player.MediaChanged += mediaChanged;
|
2019-11-11 20:10:08 +00:00
|
|
|
|
2020-02-01 01:41:45 +00:00
|
|
|
while (continueSync)
|
2019-11-11 20:10:08 +00:00
|
|
|
{
|
2020-02-01 01:41:45 +00:00
|
|
|
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);
|
|
|
|
}
|
2019-11-11 20:10:08 +00:00
|
|
|
}
|
2020-02-01 01:41:45 +00:00
|
|
|
|
2019-11-11 20:10:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|