48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
|
using System;
|
||
|
using System.Threading.Tasks;
|
||
|
using Aurora.Proto.Sync;
|
||
|
using Aurora.Proto.General;
|
||
|
using Aurora.Services.PlayerService;
|
||
|
|
||
|
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)
|
||
|
{
|
||
|
bool songIsPlaying = true;
|
||
|
PlaybackStateChangedEventHandler playbackStateChanged = (sender, e) =>
|
||
|
{
|
||
|
songIsPlaying = false;
|
||
|
};
|
||
|
|
||
|
PlayerService.Instance.PlaybackStateChanged += playbackStateChanged;
|
||
|
|
||
|
while (songIsPlaying)
|
||
|
{
|
||
|
DateTime time = Utils.TimeUtils.GetNetworkTime();
|
||
|
float position = PlayerService.Instance.CurrentMediaTime;
|
||
|
float length = PlayerService.Instance.CurrentMediaLength;
|
||
|
|
||
|
float trackTime = length * position;
|
||
|
|
||
|
Sync sync = new Sync()
|
||
|
{
|
||
|
TrackTime = trackTime,
|
||
|
ServerTime = time.Ticks
|
||
|
};
|
||
|
await responseStream.WriteAsync(sync);
|
||
|
await Task.Delay(10000);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|