Fixed playing small songs

This commit is contained in:
Master Kwoth 2017-07-02 16:54:09 +02:00
parent 322424b0a1
commit 1d1b7de20a
3 changed files with 25 additions and 14 deletions

View File

@ -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,19 +227,22 @@ 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))
.WithMusicIcon())

View File

@ -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
{

View File

@ -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");
}