Last commit was sarcasm. Added local file support. closes #61

This commit is contained in:
Master Kwoth
2016-02-25 08:30:22 +01:00
parent a421515906
commit 99d8e09ec9
4 changed files with 64 additions and 18 deletions

View File

@ -7,6 +7,13 @@ using Discord.Commands;
using MusicModule = NadekoBot.Modules.Music;
namespace NadekoBot.Classes.Music {
public enum MusicType {
Radio,
Normal,
Local
}
public class MusicControls {
private CommandEventArgs _e;
public bool NextSong { get; set; } = false;
@ -48,8 +55,10 @@ namespace NadekoBot.Classes.Music {
}
internal void AddSong(StreamRequest streamRequest) {
Stopped = false;
this.SongQueue.Add(streamRequest);
lock (_voiceLock) {
Stopped = false;
this.SongQueue.Add(streamRequest);
}
}
public MusicControls(Channel voiceChannel, CommandEventArgs e, float? vol) : this() {
@ -65,8 +74,10 @@ namespace NadekoBot.Classes.Music {
CurrentSong?.Stop();
CurrentSong = null;
if (SongQueue.Count != 0) {
CurrentSong = SongQueue[0];
SongQueue.RemoveAt(0);
lock (_voiceLock) {
CurrentSong = SongQueue[0];
SongQueue.RemoveAt(0);
}
}
else {
Stop();
@ -92,7 +103,10 @@ namespace NadekoBot.Classes.Music {
internal void Stop(bool leave = false) {
Stopped = true;
SongQueue.Clear();
CurrentSong?.Stop();
try {
CurrentSong?.Stop();
}
catch { }
CurrentSong = null;
if (leave) {
VoiceClient?.Disconnect();

View File

@ -36,11 +36,11 @@ namespace NadekoBot.Classes.Music {
public float Volume => MusicControls?.Volume ?? 1.0f;
public bool RadioLink { get; }
public MusicType LinkType { get; }
public MusicControls MusicControls;
public StreamRequest(CommandEventArgs e, string query, MusicControls mc, bool radio = false) {
public StreamRequest(CommandEventArgs e, string query, MusicControls mc, MusicType musicType = MusicType.Normal) {
if (e == null)
throw new ArgumentNullException(nameof(e));
if (query == null)
@ -48,14 +48,19 @@ namespace NadekoBot.Classes.Music {
this.MusicControls = mc;
this.Server = e.Server;
this.Query = query;
this.RadioLink = radio;
this.LinkType = musicType;
mc.AddSong(this);
}
public async Task Resolve() {
string uri = null;
try {
if (RadioLink) {
if (this.LinkType == MusicType.Local) {
uri = "\"" + Path.GetFullPath(Query) + "\"";
Title = Path.GetFileNameWithoutExtension(Query);
Provider = "Local File";
}
else if (this.LinkType == MusicType.Radio) {
uri = Query;
Title = $"{Query}";
Provider = "Radio Stream";
@ -259,7 +264,7 @@ namespace NadekoBot.Classes.Music {
// prebuffering wait stuff start
int bufferAttempts = 0;
int waitPerAttempt = 500;
int toAttemptTimes = parent.RadioLink ? 4 : 8;
int toAttemptTimes = parent.LinkType != MusicType.Normal ? 4 : 8;
while (!prebufferingComplete && bufferAttempts++ < toAttemptTimes) {
await Task.Delay(waitPerAttempt);
}