Remote playback almost working
This commit is contained in:
@ -15,7 +15,7 @@ namespace Aurora.Models.Media
|
||||
}
|
||||
|
||||
#region Properties
|
||||
public string Id { get; private set; }
|
||||
public string Id { get; protected set; }
|
||||
|
||||
#endregion Properties
|
||||
|
||||
|
83
Aurora/Models/Media/RemoteAudio.cs
Normal file
83
Aurora/Models/Media/RemoteAudio.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Aurora.Proto.Party;
|
||||
using Aurora.Proto.General;
|
||||
|
||||
namespace Aurora.Models.Media
|
||||
{
|
||||
public class RemoteAudio : BaseMedia
|
||||
{
|
||||
private RemotePartyService.RemotePartyServiceClient _client;
|
||||
private CancellationTokenSource _cancellationTokenSource;
|
||||
|
||||
#region Constructor
|
||||
public RemoteAudio(string id, RemotePartyService.RemotePartyServiceClient client)
|
||||
{
|
||||
this.Id = id;
|
||||
this._client = client;
|
||||
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
public RemoteAudio(string id, AudioMetadata metadata, RemotePartyService.RemotePartyServiceClient client)
|
||||
{
|
||||
this.Id = id;
|
||||
this._client = client;
|
||||
this.Metadata = metadata;
|
||||
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Properties
|
||||
|
||||
public override BaseMetadata Metadata { get; protected set; }
|
||||
|
||||
public override MediaTypeEnum MediaType
|
||||
{
|
||||
get { return MediaTypeEnum.Audio; }
|
||||
}
|
||||
|
||||
#endregion Properties
|
||||
|
||||
/// <summary>
|
||||
/// Override load method.
|
||||
/// </summary>
|
||||
public override async void Load()
|
||||
{
|
||||
this.DataStream = new MemoryStream();
|
||||
|
||||
using (var call = _client.GetSongStream(new SongRequest() { Id = this.Id }))
|
||||
{
|
||||
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, _cancellationTokenSource.Token);
|
||||
Console.WriteLine(string.Format("Wrote byte chunk of size {0} to output stream", buffer.Length));
|
||||
}
|
||||
Console.WriteLine("Done receiving stream");
|
||||
|
||||
}
|
||||
base.Load();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override unload method
|
||||
/// </summary>
|
||||
public override void Unload()
|
||||
{
|
||||
if (!_cancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
|
||||
//Wait for cancellation
|
||||
WaitHandle.WaitAny(new[] { _cancellationTokenSource.Token.WaitHandle });
|
||||
}
|
||||
base.Unload();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user