/// <summary> /// Adds the audio to queue. /// </summary> /// <param name="filepath">The filepath.</param> /// <param name="channelToJoin">The channel to join.</param> /// <param name="guildToJoin">The guild to join.</param> /// <returns>position in the queue</returns> public int AddAudioToQueue(string filepath, DiscordChannel channelToJoin, DiscordGuild guildToJoin) { PlayQueueElement playQueueElement = new PlayQueueElement { Filepath = filepath, ChannelToJoin = channelToJoin, GuildToJoin = guildToJoin }; playQueue.Add(playQueueElement); Program.Client.DebugLogger.Info($"Added playing file [{filepath}] to position [{playQueue.Count}] of the queue"); return(playQueue.Count); }
private async void AudioPlayingThread() { while (true) { try { PlayQueueElement elementToPlay = playQueue.Take(); Program.Client.DebugLogger.Info($"Took [{elementToPlay.Filepath}] off the queue"); // Connect if not already VoiceNextExtension voiceNextClient = Program.Client.GetVoiceNext(); VoiceNextConnection voiceNextCon = voiceNextClient.GetConnection(elementToPlay.GuildToJoin); if (voiceNextCon == null) { Program.Client.DebugLogger.Info($"Not currently connected"); Task <VoiceNextConnection> voiceNextConTask = voiceNextClient.ConnectAsync(elementToPlay.ChannelToJoin); voiceNextConTask.Wait(new TimeSpan(0, 0, 3)); if (voiceNextConTask.IsCompletedSuccessfully) { voiceNextCon = voiceNextConTask.Result; Program.Client.DebugLogger.Info($"Joined: {voiceNextCon.Channel}"); } else { Program.Client.DebugLogger.Error($"Could not join: {elementToPlay.ChannelToJoin.Name}"); continue; } } await PlayAudio(voiceNextCon, elementToPlay.Filepath); if (playQueue.Count == 0) { voiceNextCon.Disconnect(); Program.Client.DebugLogger.Info($"Leaving: {voiceNextCon.Channel}"); } } catch (Exception ex) { Program.Client.DebugLogger.Critical($"Exception was caught in the Audio Thread: {ex}"); } } }