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