Pretty good audio sync if I do say so myself :)
This commit is contained in:
@ -10,8 +10,10 @@ using LibVLCSharp.Shared;
|
||||
|
||||
namespace Aurora.Services.PlayerService
|
||||
{
|
||||
|
||||
public class PlayerService : BaseService<PlayerService>
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user