Added a little more stability (not really)
This commit is contained in:
@ -129,13 +129,15 @@ namespace Aurora.Services.PlayerService
|
||||
Sync sync = new Sync(syncStream.ResponseStream.Current);
|
||||
if (sync != null)
|
||||
{
|
||||
Utils.Time time = Utils.TimeUtils.GetNetworkTime();
|
||||
//Adjust position based on sync
|
||||
DateTime localTime = Utils.TimeUtils.GetNetworkTime();
|
||||
//Get offset converted to milliseconds
|
||||
float offset = ((localTime.Ticks - sync.ServerTime) * 100) / (1000 * 1000);
|
||||
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) / length;
|
||||
float newPosition = (sync.TrackTime + (offset + time.Elapsed.Milliseconds)) / length;
|
||||
|
||||
//Adjust position if greater than 10 percent difference
|
||||
float oldPosition = _mediaPlayer.Position;
|
||||
@ -143,7 +145,7 @@ namespace Aurora.Services.PlayerService
|
||||
newPosition - oldPosition < -0.001)
|
||||
{
|
||||
_mediaPlayer.Position = newPosition;
|
||||
Console.WriteLine("Audio synced");
|
||||
Console.WriteLine(string.Format("Audio synced: oldPosition: {0} newPosition: {1}", oldPosition, newPosition));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -166,50 +168,6 @@ namespace Aurora.Services.PlayerService
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Async method to synchronize music playback with host
|
||||
/// </summary>
|
||||
/// <param name="remoteSyncClient"></param>
|
||||
/// <returns></returns>
|
||||
private async Task Sync(RemoteSyncService.RemoteSyncServiceClient remoteSyncClient)
|
||||
{
|
||||
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
||||
using (AsyncServerStreamingCall<Sync> syncStream = remoteSyncClient
|
||||
.GetMediaSync(new Proto.General.Empty()))
|
||||
{
|
||||
try
|
||||
{
|
||||
while (await syncStream.ResponseStream.MoveNext(cancellationTokenSource.Token))
|
||||
{
|
||||
Sync sync = new Sync(syncStream.ResponseStream.Current);
|
||||
if (sync != null)
|
||||
{
|
||||
//Adjust position based on sync
|
||||
DateTime localTime = Utils.TimeUtils.GetNetworkTime();
|
||||
//Get offset converted to milliseconds
|
||||
float offset = ((localTime.Ticks - sync.ServerTime) * 100) / (1000 * 1000);
|
||||
|
||||
float length = CurrentMediaLength;
|
||||
float newPosition = (sync.TrackTime + offset) / length;
|
||||
|
||||
//Adjust position if greater than 10 percent difference
|
||||
float oldPosition = _mediaPlayer.Position;
|
||||
if (newPosition - oldPosition > 0.001 ||
|
||||
newPosition - oldPosition < -0.001)
|
||||
{
|
||||
_mediaPlayer.Position = newPosition;
|
||||
Console.WriteLine("Audio synced");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Exception caught while attempting to sync: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pause currently loaded media.
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user