This commit is contained in:
Master Kwoth 2016-03-04 14:29:14 +01:00
parent bc6e751e5f
commit 2d949333b5
2 changed files with 8 additions and 9 deletions

View File

@ -124,7 +124,7 @@ namespace NadekoBot.Classes.Music {
$"**【 {SongInfo.Title.TrimTo(55)} 】**`{(SongInfo.Provider ?? "-")}`"; $"**【 {SongInfo.Title.TrimTo(55)} 】**`{(SongInfo.Provider ?? "-")}`";
public SongInfo SongInfo { get; } public SongInfo SongInfo { get; }
private PoopyBuffer songBuffer { get; } = new PoopyBuffer(4.MiB()); private PoopyBuffer songBuffer { get; } = new PoopyBuffer(10.MiB());
private bool prebufferingComplete { get; set; } = false; private bool prebufferingComplete { get; set; } = false;
public MusicPlayer MusicPlayer { get; set; } public MusicPlayer MusicPlayer { get; set; }
@ -168,6 +168,7 @@ namespace NadekoBot.Classes.Music {
if (p != null) { if (p != null) {
try { try {
p.Kill(); p.Kill();
p.WaitForExit();
} }
catch {} catch {}
p.Dispose(); p.Dispose();
@ -176,7 +177,7 @@ namespace NadekoBot.Classes.Music {
}); });
internal async Task Play(IAudioClient voiceClient, CancellationToken cancelToken) { internal async Task Play(IAudioClient voiceClient, CancellationToken cancelToken) {
var bufferTask = BufferSong(cancelToken).ConfigureAwait(false); var bufferTask = BufferSong(cancelToken);
var bufferAttempts = 0; var bufferAttempts = 0;
const int waitPerAttempt = 500; const int waitPerAttempt = 500;
var toAttemptTimes = SongInfo.ProviderType != MusicType.Normal ? 5 : 9; var toAttemptTimes = SongInfo.ProviderType != MusicType.Normal ? 5 : 9;
@ -197,26 +198,24 @@ namespace NadekoBot.Classes.Music {
voiceClient.Wait(); voiceClient.Wait();
return; return;
} else } else
await Task.Delay(50, cancelToken); await Task.Delay(50);
else else
attempt = 0; attempt = 0;
while (this.MusicPlayer.Paused) while (this.MusicPlayer.Paused)
await Task.Delay(200, cancelToken); await Task.Delay(200, cancelToken);
buffer = AdjustVolume(buffer, MusicPlayer.Volume); buffer = AdjustVolume(buffer, read, MusicPlayer.Volume);
voiceClient.Send(buffer, 0, read); voiceClient.Send(buffer, 0, read);
} }
await bufferTask;
cancelToken.ThrowIfCancellationRequested(); cancelToken.ThrowIfCancellationRequested();
voiceClient.Clear();
} }
//stackoverflow ftw //stackoverflow ftw
private static byte[] AdjustVolume(byte[] audioSamples, float volume) { private static byte[] AdjustVolume(byte[] audioSamples, int dataLength, float volume) {
if (Math.Abs(volume - 1.0f) < 0.01f) if (Math.Abs(volume - 1.0f) < 0.01f)
return audioSamples; return audioSamples;
var array = new byte[audioSamples.Length]; var array = new byte[audioSamples.Length];
for (var i = 0; i < array.Length; i += 2) { for (var i = 0; i < dataLength; i += 2) {
// convert byte pair to int // convert byte pair to int
short buf1 = audioSamples[i + 1]; short buf1 = audioSamples[i + 1];

View File

@ -85,7 +85,7 @@ namespace NadekoBot {
public Task LoadStats() => public Task LoadStats() =>
Task.Run(() => { Task.Run(() => {
var songs = Music.MusicPlayers.Count; var songs = Music.MusicPlayers.Count(mp => mp.Value.CurrentSong != null);
var sb = new System.Text.StringBuilder(); var sb = new System.Text.StringBuilder();
sb.AppendLine("`Author: Kwoth` `Library: Discord.Net`"); sb.AppendLine("`Author: Kwoth` `Library: Discord.Net`");
sb.AppendLine($"`Bot Version: {BotVersion}`"); sb.AppendLine($"`Bot Version: {BotVersion}`");