From 351067a5203307fc0c1a14ae2be84eae71246af9 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Wed, 11 Apr 2018 14:19:57 +0200 Subject: Added possibillity for service based soundplaying --- DiscoBot/Commands/Voice.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'DiscoBot/Commands') diff --git a/DiscoBot/Commands/Voice.cs b/DiscoBot/Commands/Voice.cs index 7ffb029..9e94a30 100644 --- a/DiscoBot/Commands/Voice.cs +++ b/DiscoBot/Commands/Voice.cs @@ -2,11 +2,14 @@ { using System; using System.Collections.Generic; + using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Media; + using System.Threading; using System.Threading.Tasks; + using DiscoBot.Audio; using DiscoBot.Auxiliary; using Discord; @@ -27,12 +30,16 @@ // Create FFmpeg using the previous example var ffmpeg = CreateStream(path, volume); var output = ffmpeg.StandardOutput.BaseStream; - - var discord = Client.CreatePCMStream(AudioApplication.Music); - await output.CopyToAsync(discord); - - await discord.FlushAsync(); - + var barInvoker = new BackgroundWorker(); + barInvoker.DoWork += delegate + { + var discord = Client.CreatePCMStream(AudioApplication.Music); + output.CopyToAsync(discord); + + discord.FlushAsync(); + }; + + barInvoker.RunWorkerAsync(); } [Command("join", RunMode = RunMode.Async)] @@ -59,13 +66,14 @@ { if (Client != null) { - await SoundEffects.Play(Sound.Nooo); + var wait = SoundEffects.Play(Sound.Nooo); await Client.StopAsync(); Client = null; + wait.Wait(); } } - [Command("play")] + [Command("play", RunMode = RunMode.Async)] public async Task PlayAudioAsync(string path) { if (Client == null) -- cgit v1.2.3-54-g00ecf