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 { /// /// RPC for getting a stream of media syncs /// /// /// /// /// public override async Task GetMediaSync(Empty request, Grpc.Core.IServerStreamWriter 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); } } } }