Successfully playing a song in a party with one member
This commit is contained in:
parent
ac17d9a432
commit
759c05e53b
@ -268,9 +268,9 @@ namespace Aurora.Design.Views.Party
|
||||
Members.Add(member);
|
||||
}
|
||||
|
||||
public void PlayExecute()
|
||||
public async void PlayExecute()
|
||||
{
|
||||
PlayerService.Instance.LoadMedia(_selectedSong);
|
||||
await PlayerService.Instance.LoadMedia(_selectedSong);
|
||||
PlayerService.Instance.Play();
|
||||
}
|
||||
#endregion Private Methods
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Aurora.Models.Media
|
||||
{
|
||||
@ -19,9 +20,10 @@ namespace Aurora.Models.Media
|
||||
|
||||
#endregion Properties
|
||||
|
||||
public virtual void Load()
|
||||
public virtual Task Load()
|
||||
{
|
||||
_loaded = true;
|
||||
return Task.FromResult(default(object));
|
||||
}
|
||||
|
||||
public virtual void Unload()
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Aurora.Models.Media
|
||||
{
|
||||
@ -26,7 +27,7 @@ namespace Aurora.Models.Media
|
||||
/// <summary>
|
||||
/// Override load method.
|
||||
/// </summary>
|
||||
public override void Load()
|
||||
public override async Task Load()
|
||||
{
|
||||
if (this.DataStream != null)
|
||||
{
|
||||
@ -34,7 +35,7 @@ namespace Aurora.Models.Media
|
||||
DataStream = null;
|
||||
}
|
||||
this.DataStream = System.IO.File.OpenRead(File.FullName);
|
||||
base.Load();
|
||||
await base.Load();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Aurora.Proto.Party;
|
||||
using Aurora.Proto.General;
|
||||
|
||||
@ -45,7 +46,7 @@ namespace Aurora.Models.Media
|
||||
/// <summary>
|
||||
/// Override load method.
|
||||
/// </summary>
|
||||
public override async void Load()
|
||||
public override async Task Load()
|
||||
{
|
||||
this.DataStream = new MemoryStream();
|
||||
|
||||
@ -56,13 +57,13 @@ namespace Aurora.Models.Media
|
||||
Chunk chunk = call.ResponseStream.Current;
|
||||
byte[] buffer = chunk.Content.ToByteArray();
|
||||
|
||||
await this.DataStream.WriteAsync(buffer, 0, buffer.Length, _cancellationTokenSource.Token);
|
||||
await this.DataStream.WriteAsync(buffer, 0, buffer.Length);
|
||||
Console.WriteLine(string.Format("Wrote byte chunk of size {0} to output stream", buffer.Length));
|
||||
}
|
||||
Console.WriteLine("Done receiving stream");
|
||||
|
||||
}
|
||||
base.Load();
|
||||
await base.Load();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -70,13 +71,13 @@ namespace Aurora.Models.Media
|
||||
/// </summary>
|
||||
public override void Unload()
|
||||
{
|
||||
if (!_cancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
// if (!_cancellationTokenSource.IsCancellationRequested)
|
||||
// {
|
||||
// _cancellationTokenSource.Cancel();
|
||||
|
||||
//Wait for cancellation
|
||||
WaitHandle.WaitAny(new[] { _cancellationTokenSource.Token.WaitHandle });
|
||||
}
|
||||
// //Wait for cancellation
|
||||
// WaitHandle.WaitAny(new[] { _cancellationTokenSource.Token.WaitHandle });
|
||||
// }
|
||||
base.Unload();
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ namespace Aurora.RemoteImpl
|
||||
Grpc.Core.ServerCallContext context)
|
||||
{
|
||||
BaseMedia song = LibraryService.Instance.GetSong(request.Id);
|
||||
song.Load();
|
||||
await song.Load();
|
||||
|
||||
//Send stream
|
||||
Console.WriteLine("Begin sending file");
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Aurora.Models.Media;
|
||||
using LibVLCSharp.Shared;
|
||||
|
||||
@ -37,14 +38,14 @@ namespace Aurora.Services.PlayerService
|
||||
/// Load media into the media player.
|
||||
/// </summary>
|
||||
/// <param name="media">Media to load</param>
|
||||
public void LoadMedia(BaseMedia media)
|
||||
public async Task LoadMedia(BaseMedia media)
|
||||
{
|
||||
if (_state == PlaybackState.Playing || _state == PlaybackState.Buffering)
|
||||
{
|
||||
Unload();
|
||||
}
|
||||
_currentMedia = media;
|
||||
_currentMedia.Load();
|
||||
await _currentMedia.Load();
|
||||
var md = new Media(_libvlc, _currentMedia.DataStream);
|
||||
_mediaPlayer = new MediaPlayer(md);
|
||||
_mediaPlayer.Stopped += OnStopped;
|
||||
|
Reference in New Issue
Block a user