diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 8ca46e0a..a56d5cfa 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -109,7 +109,7 @@ namespace NadekoBot.Modules.Music .ConfigureAwait(false); if (mp.Stopped) { - (await ReplyErrorLocalized("music_queue_stopped", Format.Code(Prefix + "play")).ConfigureAwait(false)).DeleteAfter(10); + (await ReplyErrorLocalized("queue_stopped", Format.Code(Prefix + "play")).ConfigureAwait(false)).DeleteAfter(10); } queuedMessage?.DeleteAfter(10); } @@ -227,18 +227,21 @@ namespace NadekoBot.Modules.Music desc = $"`🔊` {songs[current].PrettyFullName}\n\n" + desc; - + var add = ""; if (mp.RepeatCurrentSong) - desc = "🔂 " + GetText("repeating_cur_song") + "\n\n" + desc; + add += "🔂 " + GetText("repeating_cur_song") + "\n"; else if (mp.Shuffle) - desc = "🔀 " + GetText("shuffling_playlist") + "\n\n" + desc; + add += "🔀 " + GetText("shuffling_playlist") + "\n"; else { - if(mp.Autoplay) - desc = "↪ " + GetText("autoplaying") + "\n\n" + desc; if (mp.RepeatPlaylist) - desc = "🔁 " + GetText("repeating_playlist") + "\n\n" + desc; + add += "🔁 " + GetText("repeating_playlist") + "\n"; + if (mp.Autoplay) + add += "↪ " + GetText("autoplaying") + "\n"; } + + if (!string.IsNullOrWhiteSpace(add)) + desc += add + "\n"; var embed = new EmbedBuilder() .WithAuthor(eab => eab.WithName(GetText("player_queue", curPage + 1, lastPage + 1)) diff --git a/src/NadekoBot/Services/Music/MusicPlayer.cs b/src/NadekoBot/Services/Music/MusicPlayer.cs index 97ef8ee7..48a037be 100644 --- a/src/NadekoBot/Services/Music/MusicPlayer.cs +++ b/src/NadekoBot/Services/Music/MusicPlayer.cs @@ -94,10 +94,18 @@ namespace NadekoBot.Services.Music _log.Info("Starting"); using (var b = new SongBuffer(data.Song.Uri, "")) { - var bufferSuccess = await b.StartBuffering(cancelToken); - - if (bufferSuccess == false) + var bufferTask = b.StartBuffering(cancelToken); + var timeout = Task.Delay(10000); + if (Task.WhenAny(bufferTask, timeout) == timeout) + { + _log.Info("Buffering failed due to a timeout."); continue; + } + else if (!bufferTask.Result) + { + _log.Info("Buffering failed due to a cancel or error."); + continue; + } var ac = await GetAudioClient(); if (ac == null) @@ -161,7 +169,7 @@ namespace NadekoBot.Services.Music { //if last song, and autoplay is enabled, and if it's a youtube song // do autplay magix - if (Queue.Count == data.Index && Autoplay && data.Song?.Provider == "YouTube") + if (Queue.Count - 1 == data.Index && Autoplay && data.Song?.Provider == "YouTube") { try { diff --git a/src/NadekoBot/Services/Music/SongBuffer.cs b/src/NadekoBot/Services/Music/SongBuffer.cs index fa356bb4..0e507344 100644 --- a/src/NadekoBot/Services/Music/SongBuffer.cs +++ b/src/NadekoBot/Services/Music/SongBuffer.cs @@ -48,13 +48,13 @@ namespace NadekoBot.Services.Music try { byte[] buffer = new byte[readSize]; - int bytesRead = -1; - while (!cancelToken.IsCancellationRequested && bytesRead != 0) + int bytesRead = 1; + while (!cancelToken.IsCancellationRequested && !this.p.HasExited && bytesRead > 0) { bytesRead = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, readSize, cancelToken).ConfigureAwait(false); await _outStream.WriteAsync(buffer, 0, bytesRead, cancelToken); - if (_outStream.RemainingCapacity < _outStream.Capacity * 0.5f) + if (_outStream.RemainingCapacity < _outStream.Capacity * 0.5f || bytesRead == 0) if (toReturn.TrySetResult(true)) _log.Info("Prebuffering finished"); }