コード例 #1
0
        public bool ChangeChannel(ISocketMessageChannel requester, string channelName = "")
        {
            if (m_loadedPlaylists == false && m_loadingPlaylists == false)
            {
                Utilities.Execute(async() => await LoadPlaylists(requester));
            }

            if (channelName.Equals(m_connectedChannel.Name))
            {
                return(ReconnectToVoice(requester));
            }
            else
            {
                Utilities.ExecuteAndWait(async() => await m_audioClient.StopAsync());

                if (m_audioClient.ConnectionState == ConnectionState.Disconnected && ConnectToVoice(requester, channelName))
                {
                    if (m_audioClient == null)
                    {
                        Logging.LogError(LogType.Bot, $"Audio client is not connected on server {m_guild.Name}.");
                        return(false);
                    }

                    return(true);
                }
            }

            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Leave the channel the bot is currently in
        /// </summary>
        /// <param name="guild">The guild the bot is in</param>
        /// <returns></returns>
        public async Task LeaveAudio(IGuild guild)
        {
            if (ConnectedChannels.TryRemove(guild.Id, out client))
            {
                await client.StopAsync();

                joined = false;
            }
        }
コード例 #3
0
        public static async Task deInIt()
        {
            bot.Ready -= Bot_Ready;
            if (audioClient?.ConnectionState == ConnectionState.Connected)
            {
                voiceStream?.Close();
                await audioClient.StopAsync();
            }
            await bot.StopAsync();

            await bot.LogoutAsync();
        }
コード例 #4
0
        public static async Task DeInIt()
        {
            bot.Ready           -= Bot_Ready;
            bot.MessageReceived -= Bot_MessageReceived;
            if (IsConnectedToChannel())
            {
                voiceStream?.Close();
                await audioClient.StopAsync();
            }
            await bot.StopAsync();

            await bot.LogoutAsync();
        }
コード例 #5
0
        public async Task DisconnectAsync()
        {
            if (timer != null)
            {
                await timer.DisposeAsync();
            }

            Player.Stop();
            Player.Dispose();
            await audioClient.StopAsync();

            audioClient.Dispose();
        }
コード例 #6
0
ファイル: MusicPlayer.cs プロジェクト: Dingsi/LumpiBot
 public void Stop()
 {
     Queue          = new ConcurrentQueue <Track>();
     isQueueRunning = false;
     playingTrack.CancelTokenSource.Cancel();
     try
     {
         TotalTime       = TimeSpan.Zero;
         CurrentTime     = TimeSpan.Zero;
         Music.isPlaying = false;
         audioClient.StopAsync();
     }
     catch { }
 }
コード例 #7
0
        public async Task Skip()
        {
            if (_songQueue.Count == 0)
            {
                await ReplyAsync($"Cannot skip the last song!");

                return;
            }

            await _audioClient.StopAsync();

            var nextSong = _songQueue.Dequeue();

            await PlaySong(nextSong);
        }
コード例 #8
0
        public async Task LaunchStream(string url, IAudioClient client)
        {
            playing = true;
            EmbedBuilder embed = new EmbedBuilder()
            {
                Color = new Color(235, 66, 244)
            };

            embed.Description = $"Now playing: {queue[0]}";
            await ReplyAsync("", false, embed);

            queue.RemoveAt(0);
            var output = CreateStream(url).StandardOutput.BaseStream;
            var stream = client.CreatePCMStream(AudioApplication.Music, 480);
            await output.CopyToAsync(stream);

            await stream.FlushAsync();

            if (songList.Count == 0)
            {
                playing = false;
                await client.StopAsync();
            }
            else
            {
                songList.Remove(url);
                await LaunchStream(songList[0], client);
            }
        }
コード例 #9
0
        private async Task SpeakAsync(IAudioClient client)
        {
            try
            {
                using (var reader = new WaveFileReader("Audio/Test123.wav"))
                {
                    var naudio = WaveFormatConversionStream.CreatePcmStream(reader);

                    //using (var waveOut = new WaveOutEvent())
                    //{
                    //    waveOut.Init(naudio);
                    //    Log.Logger.Debug("Playing sounds...");
                    //    waveOut.Play();
                    //    while (waveOut.PlaybackState == PlaybackState.Playing)
                    //    {
                    //        Thread.Sleep(1000);
                    //    }
                    //}

                    var dstream = client.CreatePCMStream(AudioApplication.Music);
                    await naudio.CopyToAsync(dstream);

                    dstream.Flush();
                    client.StopAsync().Wait();
                }
            }
            catch (Exception e)
            {
                Log.Logger.Error(e, "Error while sending to discord");
            }
        }
コード例 #10
0
        public async Task PlayAudioAsync()
        {
            while (Queue.Count != 0)
            {
                CurrentlyPlaying = Queue.Dequeue(); //dequeue the latest video
                try
                {
                    await DownloadVideo(CurrentlyPlaying);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
                using (var ffmpeg = CreateStream($"{id}.mp3"))
                    using (var output = ffmpeg.StandardOutput.BaseStream)
                        using (var discord = _audioClient.CreatePCMStream(AudioApplication.Mixed))
                        {
                            FFmpegId = ffmpeg.Id;
                            try
                            {
                                await output.CopyToAsync(discord);
                            }
                            finally
                            {
                                await discord.FlushAsync();

                                CurrentlyPlaying = null;
                            }
                        }
            }
            await _audioClient.StopAsync();
        }
コード例 #11
0
        public static async void LeaveChannel()
        {
            voiceStream?.Close();
            voiceStream = null;
            await audioClient.StopAsync();

            await voiceChannel.DisconnectAsync();
        }
コード例 #12
0
 public static void Dispose()
 {
     current = null;
     channel = null;
     stream.Close();
     stream.Dispose();
     client.StopAsync();
 }
コード例 #13
0
 public void Dispose()
 {
     if (_audioClient != null)
     {
         _audioClient.StopAsync().GetAwaiter().GetResult();
         _audioClient.Dispose();
     }
     _cancellationTokenSource?.Dispose();
     while (!_songQueue.IsEmpty)
     {
         _songQueue.TryDequeue(out _currentSong);
     }
     _audioClient             = null;
     _cancellationTokenSource = null;
     _currentSong             = null;
     _currentSongPath         = null;
 }
コード例 #14
0
        public async Task Stop()
        {
            started = "false";
            IVoiceChannel channel = (Context.User as IVoiceState).VoiceChannel;
            IAudioClient  client  = await channel.ConnectAsync();

            await client.StopAsync();
        }
コード例 #15
0
ファイル: AudioService.cs プロジェクト: frankfg94/MPBot
    public async Task LeaveAudio(IGuild guild)
    {
        if (ConnectedChannels.TryRemove(guild.Id, out IAudioClient client))
        {
            await client.StopAsync();

            //await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}.");
        }
    }
コード例 #16
0
        public async Task Stop(IAudioClient audioClient)
        {
            await audioClient.StopAsync();

            if (clients.ContainsValue(audioClient))
            {
                clients.Remove(clients.First(x => x.Value == audioClient).Key);
            }
        }
コード例 #17
0
ファイル: AudioPlayer.cs プロジェクト: 5l1v3r1/SpagBot
        public async Task PlayVideo(VideoInfo Video)
        {
            var ffmpeg = CreateStream(Video.DownloadUrl);

            FFMPEGProcess = ffmpeg;
            var output = ffmpeg.StandardOutput.BaseStream;

            try
            {
                await output.CopyToAsync(DiscordOutStream);

                await DiscordOutStream.FlushAsync();

                FFMPEGProcess = null;
            }
            catch (Exception)
            {
            }
            if (IsRepeated)
            {
                Videos.Insert(0, Video);
            }
            if (Videos.Count == 0)
            {
                DiscordOutStream = null;
                await AudioClient.StopAsync();
            }
            else
            {
                VideoInfo VidInfo = GetNext();
                if (IsRepeated == false)
                {
                    if (VidInfo.VideoType == VideoInfo.Types.Video)
                    {
                        SendMessage_Raised("Now Playing On SpagBot: " + VidInfo.Title, MessageClient);
                    }
                    else
                    {
                        SendMessage_Raised("Playing Livestream on Spagbot!", MessageClient);
                    }
                }
                await PlayNext();
            }
        }
コード例 #18
0
        public async Task Stop()
        {
            await client.StopAsync();

            songList.Clear();
            queue.Clear();
            await ReplyAsync($"The music was successfully stopped by {Context.User.Mention} .");

            playing = false;
        }
コード例 #19
0
        public async void DeInitPlugin()
        {
            ActGlobals.oFormActMain.PlayTtsMethod   = ActGlobals.oFormActMain.TTS;
            ActGlobals.oFormActMain.PlaySoundMethod = ActGlobals.oFormActMain.PlaySoundWmpApi;
            SaveSettings();
            try {
                bot.Ready -= Bot_Ready;
                if (audioClient?.ConnectionState == ConnectionState.Connected)
                {
                    voiceStream?.Close();
                    await audioClient.StopAsync();
                }
                await bot.StopAsync();

                await bot.LogoutAsync();
            } catch (Exception ex) {
                ActGlobals.oFormActMain.WriteExceptionLog(ex, "Error with DeInit of Discord Plugin.");
            }
            lblStatus.Text = "Plugin Exited";
        }
コード例 #20
0
        public async Task StopAsync()
        {
            _isPlaying = false;

            if (_client != null)
            {
                await _client.StopAsync();

                FinishedPlaying.Invoke(this, new FinishedPlayingEventArgs(true));
            }
        }
コード例 #21
0
    public async Task LeaveAudio(IGuild guild)
    {
        IAudioClient client;

        if (ConnectedChannels.TryRemove(guild.Id, out client))
        {
            await client.StopAsync();

            await Console.Out.WriteLineAsync(">> Audio déconnecté");
        }
    }
コード例 #22
0
ファイル: MusicService.cs プロジェクト: MrHag/DiscordBot
        public async Task DisconnectFromVoice()
        {
            if (_audioClient != null || AudioChannel != null)
            {
                await _audioClient.StopAsync();

                await AudioChannel.DisconnectAsync();

                Console.WriteLine($"Disconnected from channel {AudioChannel?.Id}");
                AudioChannel = null;
                _audioClient = null;
            }
        }
コード例 #23
0
    static void Main(string[] args)
    {
        var Client = new DiscordSocketClient();

        Client.LoginAsync(TokenType.Bot, mytoken).Wait();
        Client.StartAsync().Wait();
        var path = "path\\testfile.mp3";

        Client.Ready += async() =>
        {
            var guild   = Client.Guilds.First();
            var channel = guild.Channels.Where(x => x is SocketVoiceChannel).Select(x => x as SocketVoiceChannel).First();
            try
            {
                client = await channel.ConnectAsync();

                var reader = new Mp3FileReader(path);
                var naudio = WaveFormatConversionStream.CreatePcmStream(reader);

                dstream = client.CreatePCMStream(AudioApplication.Music);
                byte[] buffer = new byte[naudio.Length];
                int    rest   = (int)(naudio.Length - naudio.Position);
                await naudio.ReadAsync(buffer, 0, rest);

                playing = true;
                await dstream.WriteAsync(buffer, 0, rest, cancellationToken.Token);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                if (e.InnerException != null)
                {
                    Debug.WriteLine(e.InnerException.Message);
                }
            }
        };

        while (!playing)
        {
            ;
        }
        Console.ReadLine();
        cancellationToken.Cancel();
        Debug.WriteLine("Pre-Flush");
        dstream.Flush();
        Debug.WriteLine("POST-FLUSH");
        client.StopAsync().Wait();
        Client.StopAsync().Wait();
        Client.LogoutAsync().Wait();
    }
コード例 #24
0
ファイル: AudioSession.cs プロジェクト: DrogonMar/ZomoBot
 public void Dispose()
 {
     try
     {
         _shouldLoop = false;
         _currentProcess?.Kill(true);
         _audioClient.StopAsync();
         _channel.DisconnectAsync();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
コード例 #25
0
ファイル: Audio.cs プロジェクト: Xathz/Head-Non-Sub
        public static async Task PlayFileAsync(IAudioClient client, string path)
        {
            using (Process ffmpeg = CreateStream(path))
                using (Stream output = ffmpeg.StandardOutput.BaseStream)
                    using (AudioOutStream discord = client.CreatePCMStream(AudioApplication.Mixed)) {
                        try {
                            await output.CopyToAsync(discord);
                        } finally {
                            await discord.FlushAsync();
                        }
                    }

            await client.StopAsync();
        }
コード例 #26
0
ファイル: MusicService.cs プロジェクト: informaniac/MC-Bot
            public async Task PlayMusic(string MusicPath, IVoiceChannel Chan, bool Change)
            {
                try
                {
                    if (_AudioClient == null)
                    {
                        _AudioClient = await Chan.ConnectAsync();
                    }
                    else
                    {
                        if (_Process != null)
                        {
                            _Process.Close();
                            _Process.Dispose();
                        }
                        if (Change == true)
                        {
                            await _AudioClient.StopAsync();

                            _AudioClient.Dispose();
                            _AudioClient = await Chan.ConnectAsync();
                        }
                    }
                }catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }



                CreateProcess(MusicPath);
                var _Stream      = _Process.StandardOutput.BaseStream;
                var _AudioStream = _AudioClient.CreatePCMStream(AudioApplication.Music, bufferMillis: 500);
                await _Stream.CopyToAsync(_AudioStream);

                await _AudioStream.FlushAsync();
            }
コード例 #27
0
        private async Task SendAsync(IAudioClient client, string path)
        {
            // Create FFmpeg using the previous example
            using (var ffmpeg = CreateStream(path))
                using (var output = ffmpeg.StandardOutput.BaseStream)
                    using (var discord = client.CreatePCMStream(AudioApplication.Mixed))
                    {
                        try {
                            await output.CopyToAsync(discord);
                        } finally {
                            await discord.FlushAsync();

                            await client.StopAsync();
                        }
                    }
        }
コード例 #28
0
        /// <summary>
        /// Leaves the current audio channel
        /// </summary>
        /// <returns></returns>
        public async Task LeaveAudioChannel()
        {
            // No audio client
            if (m_AudioClient == null)
            {
                return;
            }

            // Stops the player loop
            await StopPlayerLoop().ConfigureAwait(false);

            await m_AudioClient.StopAsync().ConfigureAwait(false);

            // Reset values
            m_AudioClient         = null;
            m_CurrentAudioChannel = null;
        }
コード例 #29
0
 public static void Disable()
 {
     playing = false;
     if (youtubedlThread != null)
     {
         youtubedlThread.Abort();
     }
     if (sendingThread != null)
     {
         sendingThread.Abort();
     }
     if (client != null)
     {
         client.StopAsync().Wait();
     }
     if (client != null)
     {
         client.Dispose();
     }
     Enabled = false;
 }
コード例 #30
0
 public async Task LeaveChannel()
 {
     IVoiceChannel channel = (Context.User as IVoiceState).VoiceChannel;
     await _audioclient.StopAsync();
 }