Migrate aurora-sharp-desktop

This commit is contained in:
Brandon Watson
2021-03-05 23:10:12 -05:00
parent d6496355a9
commit b8c0dadf91
186 changed files with 8521 additions and 0 deletions

View File

@ -0,0 +1,35 @@
using System;
namespace Aurora.Models.Media
{
public class AudioMetadata : BaseMetadata
{
public void AutioMetadata()
{
}
/// <summary>
/// The title of the song.
/// </summary>
/// <value></value>
public string Title { get; set; }
/// <summary>
/// The artist of the song.
/// </summary>
/// <value></value>
public string Artist { get; set; }
/// <summary>
/// The album from which the song belongs.
/// </summary>
/// <value></value>
public string Album { get; set; }
/// <summary>
/// The duration of the song.
/// </summary>
/// <value></value>
public string Duration { get; set; }
}
}

View File

@ -0,0 +1,63 @@
using System;
using System.IO;
using System.Threading.Tasks;
namespace Aurora.Models.Media
{
public abstract class BaseMedia
{
private Stream _stream;
public BaseMedia()
{
//TODO need to make sure this is unique
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()
{
return Task.FromResult(default(object));
}
public virtual void Unload()
{
}
/// <summary>
/// Gets or sets the data stream that holds the song.
/// </summary>
/// <value>The data stream.</value>
public Stream DataStream
{
get
{
return _stream;
}
protected set
{
if (value != _stream)
{
_stream = value;
}
}
}
}
}

View File

@ -0,0 +1,17 @@
using System;
namespace Aurora.Models.Media
{
public class BaseMetadata
{
public BaseMetadata()
{
}
/// <summary>
/// Extra data associated with a song.
/// </summary>
/// <value></value>
public object ExtraData { get; set; }
}
}

View File

@ -0,0 +1,73 @@
using System;
using System.IO;
using System.Threading.Tasks;
namespace Aurora.Models.Media
{
public class LocalAudio : BaseMedia
{
public LocalAudio(FileInfo fileInfo)
{
File = fileInfo;
LoadMetadata();
}
public LocalAudio(LocalAudio copy)
{
File = copy.File;
LoadMetadata();
}
#region Properties
public FileInfo File { get; private set; }
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 Task Load()
{
if (this.DataStream != null)
{
DataStream.Close();
DataStream = null;
}
this.DataStream = System.IO.File.OpenRead(File.FullName);
await base.Load();
}
/// <summary>
/// Override unload method
/// </summary>
public override void Unload()
{
if (this.DataStream != null)
{
DataStream.Close();
DataStream = null;
}
base.Unload();
}
private void LoadMetadata()
{
TagLib.File tagFile = TagLib.File.Create(File.FullName);
Metadata = new AudioMetadata()
{
Title = tagFile.Tag.Title,
Album = tagFile.Tag.Album,
Artist = tagFile.Tag.FirstAlbumArtist,
ExtraData = tagFile.Tag
};
}
}
}

View File

@ -0,0 +1,9 @@
using System;
namespace Aurora.Models.Media
{
public enum MediaTypeEnum
{
Audio,
Video,
}
}

View File

@ -0,0 +1,94 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Aurora.Proto.General;
using Aurora.Proto.Party;
namespace Aurora.Models.Media
{
public class RemoteAudio : BaseMedia
{
private RemotePartyService.RemotePartyServiceClient _remotePartyService;
private CancellationTokenSource _cancellationTokenSource;
#region Constructor
public RemoteAudio(string id,
bool fromHost,
AudioMetadata metadata,
RemotePartyService.RemotePartyServiceClient partyClient)
{
this.Id = id;
this._remotePartyService = partyClient;
this.Metadata = metadata;
this.FromHost = fromHost;
_cancellationTokenSource = new CancellationTokenSource();
}
#endregion Constructor
#region Properties
public override BaseMetadata Metadata { get; protected set; }
public override MediaTypeEnum MediaType
{
get { return MediaTypeEnum.Audio; }
}
public RemotePartyService.RemotePartyServiceClient RemotePartyServiceClient
{
get
{
return _remotePartyService;
}
}
public bool FromHost { get; private set; }
#endregion Properties
/// <summary>
/// Override load method.
/// </summary>
public override async Task Load()
{
this.DataStream = new MemoryStream();
using (var call = _remotePartyService.StreamMedia(new StreamMediaRequest { Name = this.Id }))
{
try
{
_cancellationTokenSource = new CancellationTokenSource();
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);
}
Console.WriteLine("Done receiving stream");
}
catch (Exception ex)
{
Console.WriteLine("Exception caught while loading remote audio:" + ex.Message);
}
}
await 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();
}
}
}

View File

@ -0,0 +1,22 @@
using System;
namespace Aurora.Proto.Party
{
/// <summary>
/// Partial PartyMember class with a constructor that generates a new id
/// </summary>
public partial class Member
{
public Member(string id)
{
if (!string.IsNullOrWhiteSpace(id))
{
Name = id;
}
else
{
Name = Guid.NewGuid().ToString();
}
}
}
}