moved ffmpeg to using, idk maybe this helps
This commit is contained in:
parent
e5ebdb6de0
commit
7d11f94088
@ -170,12 +170,13 @@ namespace NadekoBot.Classes.Music {
|
|||||||
|
|
||||||
private async Task BufferSong() {
|
private async Task BufferSong() {
|
||||||
//start feeding the buffer
|
//start feeding the buffer
|
||||||
var p = Process.Start(new ProcessStartInfo {
|
var psi = new ProcessStartInfo {
|
||||||
FileName = "ffmpeg",
|
FileName = "ffmpeg",
|
||||||
Arguments = $"-i {Url} -f s16le -ar 48000 -ac 2 pipe:1 -loglevel quiet", //+ (NadekoBot.IsLinux ? "2> /dev/null" : "2>NUL"),
|
Arguments = $"-i {Url} -f s16le -ar 48000 -ac 2 pipe:1 -loglevel quiet", //+ (NadekoBot.IsLinux ? "2> /dev/null" : "2>NUL"),
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
});
|
};
|
||||||
|
using (var p = Process.Start(psi)) {
|
||||||
int attempt = 0;
|
int attempt = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
while (buffer.writePos - buffer.readPos > 5.MB() && State != StreamState.Completed) {
|
while (buffer.writePos - buffer.readPos > 5.MB() && State != StreamState.Completed) {
|
||||||
@ -184,11 +185,6 @@ namespace NadekoBot.Classes.Music {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (State == StreamState.Completed) {
|
if (State == StreamState.Completed) {
|
||||||
try {
|
|
||||||
p.CancelOutputRead();
|
|
||||||
p.Close();
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
Console.WriteLine("Buffering canceled, stream is completed.");
|
Console.WriteLine("Buffering canceled, stream is completed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -212,11 +208,6 @@ namespace NadekoBot.Classes.Music {
|
|||||||
//Console.WriteLine($"Read: {read}");
|
//Console.WriteLine($"Read: {read}");
|
||||||
if (read == 0) {
|
if (read == 0) {
|
||||||
if (attempt == 5) {
|
if (attempt == 5) {
|
||||||
try {
|
|
||||||
p.Dispose();
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
|
|
||||||
Console.WriteLine($"Didn't read anything from the stream for {attempt} attempts. {buffer.Length / 1.MB()}MB length");
|
Console.WriteLine($"Didn't read anything from the stream for {attempt} attempts. {buffer.Length / 1.MB()}MB length");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -233,6 +224,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal async Task StartPlayback() {
|
internal async Task StartPlayback() {
|
||||||
Console.WriteLine("Starting playback.");
|
Console.WriteLine("Starting playback.");
|
||||||
@ -241,7 +233,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
if (parent.OnBuffering != null)
|
if (parent.OnBuffering != null)
|
||||||
parent.OnBuffering();
|
parent.OnBuffering();
|
||||||
|
|
||||||
Task.Run(async () => {
|
Task.Factory.StartNew(async () => {
|
||||||
await BufferSong();
|
await BufferSong();
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user