Fixed pause

This commit is contained in:
Kwoth 2016-12-22 08:12:51 +01:00
parent 58f2540083
commit 34a9a3dd5f
2 changed files with 23 additions and 14 deletions

View File

@ -170,10 +170,15 @@ namespace NadekoBot.Modules.Music.Classes
if (slowconnection) if (slowconnection)
{ {
_log.Warn("Slow connection has disrupted music, waiting a bit for buffer"); _log.Warn("Slow connection has disrupted music, waiting a bit for buffer");
await Task.Delay(1000, cancelToken).ConfigureAwait(false); await Task.Delay(1000, cancelToken).ConfigureAwait(false);
nextTime = Environment.TickCount + milliseconds;
} }
else else
{
await Task.Delay(100, cancelToken).ConfigureAwait(false); await Task.Delay(100, cancelToken).ConfigureAwait(false);
nextTime = Environment.TickCount + milliseconds;
}
} }
else else
attempt = 0; attempt = 0;
@ -182,7 +187,10 @@ namespace NadekoBot.Modules.Music.Classes
attempt = 0; attempt = 0;
while (this.MusicPlayer.Paused) while (this.MusicPlayer.Paused)
{
await Task.Delay(200, cancelToken).ConfigureAwait(false); await Task.Delay(200, cancelToken).ConfigureAwait(false);
nextTime = Environment.TickCount + milliseconds;
}
buffer = AdjustVolume(buffer, MusicPlayer.Volume); buffer = AdjustVolume(buffer, MusicPlayer.Volume);

View File

@ -25,21 +25,21 @@ namespace NadekoBot.Modules.Music.Classes
_log = LogManager.GetCurrentClassLogger(); _log = LogManager.GetCurrentClassLogger();
} }
MusicPlayer MusicPlayer; MusicPlayer MusicPlayer { get; }
private string Basename; private string Basename { get; }
private SongInfo SongInfo; private SongInfo SongInfo { get; }
private int SkipTo; private int SkipTo { get; }
private int MaxFileSize = 2.MiB(); private int MaxFileSize { get; } = 2.MiB();
private long FileNumber = -1; private long FileNumber = -1;
private long NextFileToRead = 0; private long NextFileToRead = 0;
public bool BufferingCompleted { get; private set;} = false; public bool BufferingCompleted { get; private set; } = false;
private ulong CurrentBufferSize = 0; private ulong CurrentBufferSize = 0;
@ -76,7 +76,8 @@ namespace NadekoBot.Modules.Music.Classes
try try
{ {
outStream.Dispose(); outStream.Dispose();
}catch { } }
catch { }
outStream = new FileStream(Basename + "-" + ++FileNumber, FileMode.Append, FileAccess.Write, FileShare.Read); outStream = new FileStream(Basename + "-" + ++FileNumber, FileMode.Append, FileAccess.Write, FileShare.Read);
currentFileSize = bytesRead; currentFileSize = bytesRead;
} }
@ -108,8 +109,8 @@ Check the guides for your platform on how to setup ffmpeg correctly:
} }
finally finally
{ {
if(outStream != null) if (outStream != null)
outStream.Dispose(); outStream.Dispose();
Console.WriteLine($"Buffering done."); Console.WriteLine($"Buffering done.");
if (p != null) if (p != null)
{ {
@ -130,7 +131,7 @@ Check the guides for your platform on how to setup ffmpeg correctly:
private string GetNextFile() private string GetNextFile()
{ {
string filename = Basename + "-" + NextFileToRead; string filename = Basename + "-" + NextFileToRead;
if (NextFileToRead != 0) if (NextFileToRead != 0)
{ {
try try
@ -151,7 +152,7 @@ Check the guides for your platform on how to setup ffmpeg correctly:
private void CleanFiles() private void CleanFiles()
{ {
for (long i = NextFileToRead - 1 ; i <= FileNumber; i++) for (long i = NextFileToRead - 1; i <= FileNumber; i++)
{ {
try try
{ {
@ -169,7 +170,7 @@ Check the guides for your platform on how to setup ffmpeg correctly:
public override bool CanWrite => false; public override bool CanWrite => false;
public override long Length => (long) CurrentBufferSize; public override long Length => (long)CurrentBufferSize;
public override long Position { get; set; } = 0; public override long Position { get; set; } = 0;
@ -178,7 +179,7 @@ Check the guides for your platform on how to setup ffmpeg correctly:
public override int Read(byte[] buffer, int offset, int count) public override int Read(byte[] buffer, int offset, int count)
{ {
int read = CurrentFileStream.Read(buffer, offset, count); int read = CurrentFileStream.Read(buffer, offset, count);
if(read < count) if (read < count)
{ {
if (!BufferingCompleted || IsNextFileReady()) if (!BufferingCompleted || IsNextFileReady())
{ {
@ -215,4 +216,4 @@ Check the guides for your platform on how to setup ffmpeg correctly:
base.Dispose(); base.Dispose();
} }
} }
} }