コード例 #1
0
ファイル: AudioService.cs プロジェクト: justinasci/Discordium
        public async Task <string> AddSong(IGuild guild, IVoiceChannel target, string uri)
        {
            string fname      = HashFileName(uri);
            bool   gotTheFile = await getSongFromYoutubes(uri, fname);

            if (gotTheFile)
            {
                GuildVoiceContext audiocon;
                if (!_guildVoiceContext.TryGetValue(guild.Id, out audiocon))
                {
                    audiocon       = new GuildVoiceContext();
                    audiocon.queue = new Queue <Song>();

                    if (!_guildVoiceContext.TryAdd(guild.Id, audiocon))
                    {
                        return(null);
                    }
                }
                audiocon.queue.Enqueue(new Song(fname));
                await JoinAudio(guild, target, audiocon);

                return(fname);
            }

            return(null);
        }
コード例 #2
0
ファイル: AudioService.cs プロジェクト: justinasci/Discordium
        public async Task LeaveAudio(IGuild guild, GuildVoiceContext gvc = null)
        {
            if (gvc == null)
            {
                if (!_guildVoiceContext.TryGetValue(guild.Id, out gvc))
                {
                    Console.Write("ERRORS LEAVING");
                    return;
                }
            }

            await gvc.client.StopAsync();

            gvc.client = null;
        }
コード例 #3
0
ファイル: AudioService.cs プロジェクト: justinasci/Discordium
        public async Task JoinAudio(IGuild guid, IVoiceChannel target, GuildVoiceContext gvc)
        {
            if (gvc.client != null)
            {
                return;
            }

            if (target.Id == guid.Id)
            {
                return;
            }
            gvc.client = await target.ConnectAsync();

            Console.WriteLine("Connected voice on: " + guid.Name);

            if (gvc.queue.Count > 0)
            {
                Song   song      = gvc.NextSong();
                string filnename = "audio\\" + song.filename + ".m4a";
                await SendAudioAsync(guid, null, filnename, gvc);
            }
        }
コード例 #4
0
ファイル: AudioService.cs プロジェクト: justinasci/Discordium
        private async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string path, GuildVoiceContext gvc)
        {
            gvc.player = CreateStreamFFMPEG(path);
            var ffmpeg  = gvc.player;
            var output  = ffmpeg.StandardOutput.BaseStream;
            var discord = gvc.client.CreatePCMStream(AudioApplication.Mixed, 96000);
            await output.CopyToAsync(discord);

            await discord.FlushAsync();

            if (gvc.queue.Count > 0)
            {
                Song   song      = gvc.NextSong();
                string filnename = "audio\\" + song.filename + ".m4a";
                await SendAudioAsync(guild, channel, filnename, gvc);
            }
            if (gvc.client.ConnectionState == ConnectionState.Connected && gvc.queue.Count == 0)
            {
                await LeaveAudio(guild);
            }
        }