From e505d407c20640cba2007d2b647c4f1a56c65a2d Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 27 Jan 2016 06:33:31 +0100 Subject: [PATCH] showing stats every 5 secs now --- NadekoBot/Classes/Music/MusicControls.cs | 2 -- NadekoBot/Classes/Music/StreamRequest.cs | 26 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/NadekoBot/Classes/Music/MusicControls.cs b/NadekoBot/Classes/Music/MusicControls.cs index 0347f516..f57a4880 100644 --- a/NadekoBot/Classes/Music/MusicControls.cs +++ b/NadekoBot/Classes/Music/MusicControls.cs @@ -2,8 +2,6 @@ using Discord.Audio; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; namespace NadekoBot.Classes.Music { diff --git a/NadekoBot/Classes/Music/StreamRequest.cs b/NadekoBot/Classes/Music/StreamRequest.cs index a6a55b08..162e8b85 100644 --- a/NadekoBot/Classes/Music/StreamRequest.cs +++ b/NadekoBot/Classes/Music/StreamRequest.cs @@ -12,6 +12,7 @@ using System.IO; using System.Diagnostics; using NadekoBot.Extensions; using System.Threading; +using Timer = System.Timers.Timer; namespace NadekoBot.Classes.Music { public enum StreamState { @@ -112,6 +113,8 @@ namespace NadekoBot.Classes.Music { private readonly object _bufferLock = new object(); private CancellationTokenSource cancelSource; + public static Timer logTimer = new Timer(); + public MusicStreamer(StreamRequest parent, string directUrl, Channel channel) { this.parent = parent; this.channel = channel; @@ -120,7 +123,25 @@ namespace NadekoBot.Classes.Music { Console.WriteLine("Created new streamer"); State = StreamState.Queued; cancelSource = new CancellationTokenSource(); + + if (!logTimer.Enabled) { + logTimer.Interval = 5000; + logTimer.Start(); + } + logTimer.Elapsed += LogTimer_Elapsed; } + + private void LogTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { + if (cancelSource.IsCancellationRequested) { + logTimer.Elapsed -= LogTimer_Elapsed; + return; + } + Console.WriteLine($"Music stats for {string.Join("", parent.Title.Take(parent.Title.Length > 10 ? 10 : parent.Title.Length))}"); + Console.WriteLine($"Server: {parent.Server.Name}"); + Console.WriteLine($"Title: - Length:{buffer.Length * 1.0f / 1.MB()}MB Status: {State} - Canceled: { cancelSource.IsCancellationRequested}"); + Console.WriteLine("--------------------------------"); + } + //todo app will crash if song is too long, should load only next 20-ish seconds private async Task BufferSong() { Console.WriteLine("Buffering..."); @@ -129,15 +150,14 @@ namespace NadekoBot.Classes.Music { FileName = "ffmpeg", Arguments = $"-i {Url} -f s16le -ar 48000 -ac 2 pipe:1", UseShellExecute = false, - RedirectStandardError = false, RedirectStandardOutput = true, CreateNoWindow = true, + WindowStyle = ProcessWindowStyle.Hidden, }); - while (true) { while (buffer.writePos - buffer.readPos > 2.MB() && !cancelSource.IsCancellationRequested) { - Console.WriteLine($"Got over 2MB more, waiting. Data length:{buffer.Length * 1.0f / 1.MB()}MB"); + await Task.Delay(1000); }