Пример #1
0
        public StreamTask(DiscordClient client, StreamRequest streamRequest, Stream bufferingStream)
        {
            this.streamRequest   = streamRequest;
            this.bufferingStream = bufferingStream;
            this.client          = client;

            State = StreamTaskState.Queued;
        }
Пример #2
0
 private void LoadNextSong()
 {
     if (SongQueue.Count == 0 || !SongQueue[0].LinkResolved)
     {
         if (CurrentSong != null)
         {
             CurrentSong.Cancel();
         }
         CurrentSong = null;
         return;
     }
     CurrentSong = SongQueue[0];
     SongQueue.RemoveAt(0);
     CurrentSong.Start();
     return;
 }
Пример #3
0
        private async Task QueueSong(CommandEventArgs e, string query, bool silent = false, bool radio = false)
        {
            if (e.User.VoiceChannel?.Server != e.Server)
            {
                await e.Channel.SendMessage("💢 You need to be in the voice channel on this server.");

                return;
            }

            if (string.IsNullOrWhiteSpace(query) || query.Length < 3)
            {
                return;
            }

            query = query.Trim();

            if (IsRadioLink(query))
            {
                radio = true;
                query = await HandleStreamContainers(query);
            }

            if (musicPlayers.ContainsKey(e.Server) == false)
            {
                float?vol = null;
                float throwAway;
                if (musicVolumes.TryGetValue(e.Server.Id, out throwAway))
                {
                    vol = throwAway;
                }

                if (!musicPlayers.TryAdd(e.Server, new MusicControls(e.User.VoiceChannel, e, vol)))
                {
                    await e.Channel.SendMessage("Failed to create a music player for this server.");

                    return;
                }
            }

            var player = musicPlayers[e.Server];

            if (player.SongQueue.Count >= 25)
            {
                return;
            }

            try {
                var sr = new StreamRequest(e, query, player, radio);

                if (sr == null)
                {
                    throw new NullReferenceException("StreamRequest is null.");
                }

                Message qmsg = null;
                Message msg  = null;
                if (!silent)
                {
                    qmsg = await e.Channel.SendMessage("🎵 `Searching / Resolving...`");

                    sr.OnResolvingFailed += async(err) => {
                        await qmsg?.Edit($"💢 🎵 `Resolving failed` for **{query}**");
                    };
                    sr.OnQueued += async() => {
                        await qmsg?.Edit($"🎵`Queued`{sr.FullPrettyName}");
                    };
                }
                sr.OnCompleted += async() => {
                    MusicControls mc;
                    if (musicPlayers.TryGetValue(e.Server, out mc))
                    {
                        if (mc.SongQueue.Count == 0)
                        {
                            mc.Stop();
                        }
                    }
                    await e.Channel.SendMessage($"🎵`Finished`{sr.FullPrettyName}");
                };
                sr.OnStarted += async() => {
                    var msgTxt = $"🎵`Playing`{sr.FullPrettyName} `Vol: {(int)(player.Volume * 100)}%`";
                    if (msg == null)
                    {
                        await e.Channel.SendMessage(msgTxt);
                    }
                    else
                    {
                        await msg.Edit(msgTxt);
                    }
                    qmsg?.Delete();
                };
                sr.OnBuffering += async() => {
                    msg = await e.Channel.SendMessage($"🎵`Buffering...`{sr.FullPrettyName}");
                };
                await sr.Resolve();
            } catch (Exception ex) {
                Console.WriteLine();
                await e.Channel.SendMessage($"💢 {ex.Message}");

                return;
            }
        }
Пример #4
0
 public TranscodingTask(StreamRequest streamRequest, Stream bufferingStream)
 {
     this.streamRequest   = streamRequest;
     this.bufferingStream = bufferingStream;
 }