UNSTABLE - Music bugfixes, pat command
This commit is contained in:
@@ -4,9 +4,11 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using MusicModule = NadekoBot.Modules.Music;
|
||||
|
||||
namespace NadekoBot.Classes.Music {
|
||||
public class MusicControls {
|
||||
private CommandEventArgs _e;
|
||||
public bool NextSong = false;
|
||||
public IAudioClient Voice;
|
||||
|
||||
@@ -17,7 +19,7 @@ namespace NadekoBot.Classes.Music {
|
||||
public bool IsPaused { get; internal set; } = false;
|
||||
public bool Stopped { get; private set; }
|
||||
|
||||
public Channel VoiceChannel;
|
||||
public Channel VoiceChannel = null;
|
||||
|
||||
public IAudioClient VoiceClient = null;
|
||||
|
||||
@@ -34,13 +36,16 @@ namespace NadekoBot.Classes.Music {
|
||||
NextSong = false;
|
||||
await LoadNextSong();
|
||||
}
|
||||
await Task.Delay(1000);
|
||||
await Task.Delay(500);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public MusicControls(Channel voiceChannel) : this() {
|
||||
public MusicControls(Channel voiceChannel, CommandEventArgs e) : this() {
|
||||
if (voiceChannel == null)
|
||||
throw new ArgumentNullException(nameof(voiceChannel));
|
||||
VoiceChannel = voiceChannel;
|
||||
_e = e;
|
||||
}
|
||||
|
||||
public async Task LoadNextSong() {
|
||||
@@ -56,14 +61,13 @@ namespace NadekoBot.Classes.Music {
|
||||
}
|
||||
|
||||
try {
|
||||
if (VoiceChannel == null)
|
||||
VoiceChannel = CurrentSong.Channel;
|
||||
if (VoiceClient == null)
|
||||
VoiceClient = await NadekoBot.client.Audio().Join(VoiceChannel);
|
||||
await CurrentSong.Start();
|
||||
} catch (Exception ex) {
|
||||
Console.WriteLine($"Starting failed: {ex}");
|
||||
CurrentSong?.Stop();
|
||||
CurrentSong = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +82,9 @@ namespace NadekoBot.Classes.Music {
|
||||
CurrentSong = null;
|
||||
VoiceClient?.Disconnect();
|
||||
VoiceClient = null;
|
||||
|
||||
MusicControls throwAwayValue;
|
||||
MusicModule.musicPlayers.TryRemove(_e.Server, out throwAwayValue);
|
||||
}
|
||||
|
||||
internal bool TogglePause() => IsPaused = !IsPaused;
|
||||
|
@@ -24,7 +24,6 @@ namespace NadekoBot.Classes.Music {
|
||||
}
|
||||
|
||||
public class StreamRequest {
|
||||
public Channel Channel { get; }
|
||||
public Server Server { get; }
|
||||
public User User { get; }
|
||||
public string Query { get; }
|
||||
@@ -48,7 +47,6 @@ namespace NadekoBot.Classes.Music {
|
||||
this.Server = e.Server;
|
||||
this.Query = query;
|
||||
Task.Run(() => ResolveStreamLink());
|
||||
Console.WriteLine("6");
|
||||
mc.SongQueue.Add(this);
|
||||
}
|
||||
|
||||
@@ -76,7 +74,7 @@ namespace NadekoBot.Classes.Music {
|
||||
return;
|
||||
}
|
||||
|
||||
musicStreamer = new MusicStreamer(this, video.DownloadUrl, Channel);
|
||||
musicStreamer = new MusicStreamer(this, video.DownloadUrl);
|
||||
if (OnQueued != null)
|
||||
OnQueued();
|
||||
return;
|
||||
@@ -126,7 +124,6 @@ namespace NadekoBot.Classes.Music {
|
||||
}
|
||||
|
||||
public class MusicStreamer {
|
||||
private Channel channel;
|
||||
private DualStream buffer;
|
||||
|
||||
public StreamState State { get; internal set; }
|
||||
@@ -138,9 +135,8 @@ namespace NadekoBot.Classes.Music {
|
||||
private readonly object _bufferLock = new object();
|
||||
private bool prebufferingComplete = false;
|
||||
|
||||
public MusicStreamer(StreamRequest parent, string directUrl, Channel channel) {
|
||||
public MusicStreamer(StreamRequest parent, string directUrl) {
|
||||
this.parent = parent;
|
||||
this.channel = channel;
|
||||
this.buffer = new DualStream();
|
||||
this.Url = directUrl;
|
||||
Console.WriteLine("Created new streamer");
|
||||
@@ -206,7 +202,7 @@ namespace NadekoBot.Classes.Music {
|
||||
read = await p.StandardOutput.BaseStream.ReadAsync(buf, 0, 1024);
|
||||
//Console.WriteLine($"Read: {read}");
|
||||
if (read == 0) {
|
||||
if (attempt == 2) {
|
||||
if (attempt == 5) {
|
||||
try {
|
||||
p.CancelOutputRead();
|
||||
p.Close();
|
||||
@@ -216,7 +212,7 @@ namespace NadekoBot.Classes.Music {
|
||||
return;
|
||||
} else {
|
||||
++attempt;
|
||||
await Task.Delay(10);
|
||||
await Task.Delay(20);
|
||||
}
|
||||
} else {
|
||||
attempt = 0;
|
||||
@@ -296,9 +292,8 @@ namespace NadekoBot.Classes.Music {
|
||||
internal void Stop() {
|
||||
Console.WriteLine("Stopping playback");
|
||||
if (State != StreamState.Completed) {
|
||||
if(State == StreamState.Playing)
|
||||
parent.OnCompleted();
|
||||
State = StreamState.Completed;
|
||||
parent.OnCompleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user