diff --git a/Aurora/Design/Views/Party/PartyViewModel.cs b/Aurora/Design/Views/Party/PartyViewModel.cs index c640c0c..fb71a1f 100644 --- a/Aurora/Design/Views/Party/PartyViewModel.cs +++ b/Aurora/Design/Views/Party/PartyViewModel.cs @@ -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 diff --git a/Aurora/Models/Media/BaseMedia.cs b/Aurora/Models/Media/BaseMedia.cs index ae71cf8..0e31597 100644 --- a/Aurora/Models/Media/BaseMedia.cs +++ b/Aurora/Models/Media/BaseMedia.cs @@ -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() diff --git a/Aurora/Models/Media/LocalAudio.cs b/Aurora/Models/Media/LocalAudio.cs index c96d8d4..6b6ec7b 100644 --- a/Aurora/Models/Media/LocalAudio.cs +++ b/Aurora/Models/Media/LocalAudio.cs @@ -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 /// /// Override load method. /// - 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(); } /// diff --git a/Aurora/Models/Media/RemoteAudio.cs b/Aurora/Models/Media/RemoteAudio.cs index bc4a515..f3dfb53 100644 --- a/Aurora/Models/Media/RemoteAudio.cs +++ b/Aurora/Models/Media/RemoteAudio.cs @@ -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 /// /// Override load method. /// - 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(); } /// @@ -70,13 +71,13 @@ namespace Aurora.Models.Media /// 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(); } } diff --git a/Aurora/RemoteImpl/RemotePartyImpl.cs b/Aurora/RemoteImpl/RemotePartyImpl.cs index 93ebf30..14b53e0 100644 --- a/Aurora/RemoteImpl/RemotePartyImpl.cs +++ b/Aurora/RemoteImpl/RemotePartyImpl.cs @@ -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"); diff --git a/Aurora/Services/PlayerService/PlayerService.cs b/Aurora/Services/PlayerService/PlayerService.cs index 61501dc..008f14a 100644 --- a/Aurora/Services/PlayerService/PlayerService.cs +++ b/Aurora/Services/PlayerService/PlayerService.cs @@ -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. /// /// Media to load - 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;