First pass at syncing worked with some bug fixes

This commit is contained in:
watsonb8
2019-11-12 20:09:45 -05:00
parent 1acc383e90
commit 3398d145ac
8 changed files with 128 additions and 66 deletions

View File

@ -6,35 +6,39 @@ namespace Aurora.Models.Media
{
public abstract class BaseMedia
{
private bool _loaded;
private Stream _stream;
public BaseMedia()
{
_loaded = false;
Id = Guid.NewGuid().ToString();
}
#region Properties
public string Id { get; protected set; }
public abstract MediaTypeEnum MediaType { get; }
public abstract BaseMetadata Metadata { get; protected set; }
public bool IsLoaded
{
get
{
return DataStream != null;
}
}
#endregion Properties
public virtual Task Load()
{
_loaded = true;
return Task.FromResult(default(object));
}
public virtual void Unload()
{
_loaded = false;
}
public abstract MediaTypeEnum MediaType { get; }
public abstract BaseMetadata Metadata { get; protected set; }
/// <summary>
/// Gets or sets the data stream that holds the song.

View File

@ -12,6 +12,12 @@ namespace Aurora.Models.Media
LoadMetadata();
}
public LocalAudio(LocalAudio copy)
{
File = copy.File;
LoadMetadata();
}
#region Properties
public FileInfo File { get; private set; }

View File

@ -15,7 +15,9 @@ namespace Aurora.Models.Media
private CancellationTokenSource _cancellationTokenSource;
#region Constructor
public RemoteAudio(string id, AudioMetadata metadata,
public RemoteAudio(string id,
bool fromHost,
AudioMetadata metadata,
RemotePlaybackService.RemotePlaybackServiceClient playbackClient,
RemoteSyncService.RemoteSyncServiceClient syncClient)
{
@ -23,6 +25,7 @@ namespace Aurora.Models.Media
this._remotePlaybackClient = playbackClient;
this._remoteSyncClient = syncClient;
this.Metadata = metadata;
this.FromHost = fromHost;
_cancellationTokenSource = new CancellationTokenSource();
}
@ -46,6 +49,7 @@ namespace Aurora.Models.Media
}
}
public bool FromHost { get; private set; }
#endregion Properties
/// <summary>
@ -56,15 +60,21 @@ namespace Aurora.Models.Media
this.DataStream = new MemoryStream();
using (var call = _remotePlaybackClient.GetSongStream(new SongRequest() { Id = this.Id }))
{
while (await call.ResponseStream.MoveNext(_cancellationTokenSource.Token))
try
{
Chunk chunk = call.ResponseStream.Current;
byte[] buffer = chunk.Content.ToByteArray();
while (await call.ResponseStream.MoveNext(_cancellationTokenSource.Token))
{
Chunk chunk = call.ResponseStream.Current;
byte[] buffer = chunk.Content.ToByteArray();
await this.DataStream.WriteAsync(buffer, 0, buffer.Length);
await this.DataStream.WriteAsync(buffer, 0, buffer.Length);
}
Console.WriteLine("Done receiving stream");
}
catch (Exception ex)
{
Console.WriteLine("Exception caught while loading remote audio:" + ex.Message);
}
Console.WriteLine("Done receiving stream");
}
await base.Load();
}