diff --git a/Aurora/Design/Components/MemberList/MemberList.xaml.cs b/Aurora/Design/Components/MemberList/MemberList.xaml.cs index 9bd916e..f676404 100644 --- a/Aurora/Design/Components/MemberList/MemberList.xaml.cs +++ b/Aurora/Design/Components/MemberList/MemberList.xaml.cs @@ -10,7 +10,7 @@ namespace Aurora.Design.Components.MemberList public partial class MemberList : ContentView { private static ObservableCollection _newSource; - private static NotifyCollectionChangedEventHandler _collectionChangedHandler; + // private static NotifyCollectionChangedEventHandler _collectionChangedHandler; public MemberList() { InitializeComponent(); diff --git a/Aurora/Design/Views/Party/PartyViewModel.cs b/Aurora/Design/Views/Party/PartyViewModel.cs index 0ea29ee..2c06903 100644 --- a/Aurora/Design/Views/Party/PartyViewModel.cs +++ b/Aurora/Design/Views/Party/PartyViewModel.cs @@ -172,9 +172,10 @@ namespace Aurora.Design.Views.Party /// Called by framework when view becomes inactive /// /// - public override async Task OnInactive() + public override Task OnInactive() { _client.StopEvents(); + return Task.FromResult(null); } /// diff --git a/Aurora/Proto/sync.proto b/Aurora/Proto/sync.proto index ef31739..7235163 100644 --- a/Aurora/Proto/sync.proto +++ b/Aurora/Proto/sync.proto @@ -10,6 +10,6 @@ service RemoteSyncService { } message Sync { - int64 serverTime = 1; - float trackTime = 2; + int64 serverTimeTicks = 1; + float trackPosition= 2; } \ No newline at end of file diff --git a/Aurora/RemoteImpl/RemoteEventImpl.cs b/Aurora/RemoteImpl/RemoteEventImpl.cs index 78f7480..5bbe42e 100644 --- a/Aurora/RemoteImpl/RemoteEventImpl.cs +++ b/Aurora/RemoteImpl/RemoteEventImpl.cs @@ -23,7 +23,7 @@ namespace Aurora.RemoteImpl /// The response stream /// gRPC client context /// - public async override Task GetEvents(EventsRequest request, + public override Task GetEvents(EventsRequest request, Grpc.Core.IServerStreamWriter responseStream, Grpc.Core.ServerCallContext context) { @@ -41,6 +41,7 @@ namespace Aurora.RemoteImpl EventManager.Instance.AddEventHandler(callback, Combine(new string[] { context.Peer, request.ClientId })); are.WaitOne(); + return Task.FromResult(null); } /// diff --git a/Aurora/RemoteImpl/RemoteSyncImpl.cs b/Aurora/RemoteImpl/RemoteSyncImpl.cs index ddfc214..eddaac0 100644 --- a/Aurora/RemoteImpl/RemoteSyncImpl.cs +++ b/Aurora/RemoteImpl/RemoteSyncImpl.cs @@ -33,13 +33,12 @@ namespace Aurora.RemoteImpl while (continueSync) { - Utils.Time networkTime = Utils.TimeUtils.GetNetworkTime(); float length = PlayerService.Instance.CurrentMediaLength; Sync sync = new Sync() { - TrackTime = length * PlayerService.Instance.CurrentMediaPosition, - ServerTime = networkTime.DateTime.Ticks + networkTime.Elapsed.Ticks + TrackPosition = PlayerService.Instance.CurrentMediaPosition, + ServerTimeTicks = Utils.TimeUtils.GetNetworkTime().DateTime.Ticks }; await responseStream.WriteAsync(sync); Console.WriteLine("Sent Sync"); diff --git a/Aurora/Services/PlayerService/PlayerService.cs b/Aurora/Services/PlayerService/PlayerService.cs index c2cfc93..ddab44a 100644 --- a/Aurora/Services/PlayerService/PlayerService.cs +++ b/Aurora/Services/PlayerService/PlayerService.cs @@ -10,8 +10,10 @@ using LibVLCSharp.Shared; namespace Aurora.Services.PlayerService { + public class PlayerService : BaseService { + private const long _ticksPerMillisecond = 10000; private BaseMedia _currentMedia; private MediaPlayer _mediaPlayer; private LibVLC _libvlc; @@ -134,10 +136,10 @@ namespace Aurora.Services.PlayerService DateTime localTime = time.DateTime; //Get offset - elapsed time converted to milliseconds - float offset = (((localTime.Ticks - sync.ServerTime) * 100) / (1000 * 1000)); - float length = CurrentMediaLength; - float newPosition = (sync.TrackTime + (offset + time.Elapsed.Milliseconds)) / length; + float offset = (localTime.Ticks - sync.ServerTimeTicks) * _ticksPerMillisecond; + + float newPosition = (sync.TrackPosition + offset); //Adjust position if greater than 10 percent difference float oldPosition = _mediaPlayer.Position; @@ -145,7 +147,15 @@ namespace Aurora.Services.PlayerService newPosition - oldPosition < -0.001) { _mediaPlayer.Position = newPosition; - Console.WriteLine(string.Format("Audio synced: oldPosition: {0} newPosition: {1}", oldPosition, newPosition)); + Console.WriteLine(string.Format("**Audio synced**")); + Console.WriteLine(string.Format("Remote Server Time {0}", new DateTime(sync.ServerTimeTicks).ToLongTimeString())); + Console.WriteLine(string.Format("Remote Track Time: {0}", sync.TrackPosition)); + Console.WriteLine(string.Format("Local Server Time: {0}", time.DateTime.ToLongTimeString())); + Console.WriteLine(string.Format("Local Track Time: {0}", _mediaPlayer.Position)); + Console.WriteLine(string.Format("Offset: {0}", offset)); + Console.WriteLine(string.Format("Old Position: {0}", oldPosition)); + Console.WriteLine(string.Format("New Position: {0}", newPosition)); + } } } @@ -158,7 +168,6 @@ namespace Aurora.Services.PlayerService }); syncTask.Start(); - // Task syncTask = Task.Run(() => Sync(remoteSyncClient)); } } diff --git a/Aurora/Utils/TimeUtils.cs b/Aurora/Utils/TimeUtils.cs index 9d0ce53..c58516b 100644 --- a/Aurora/Utils/TimeUtils.cs +++ b/Aurora/Utils/TimeUtils.cs @@ -45,13 +45,14 @@ namespace Aurora.Utils socket.ReceiveTimeout = 3000; stopwatch.Start(); socket.Send(ntpData); + stopwatch.Stop(); socket.Receive(ntpData); socket.Close(); } //Offset to get to the "Transmit Timestamp" field (time at which the reply //departed the server for the client, in 64-bit timestamp format." - const byte serverReplyTime = 40; + byte serverReplyTime = 40; //Get the seconds part ulong intPart = BitConverter.ToUInt32(ntpData, serverReplyTime);