コード例 #1
0
        /// <summary>
        ///     Plays the specified track.
        /// </summary>
        /// <param name="track">An instance of <see cref="LavaTrack" />.</param>
        public async Task PlayAsync(LavaTrack track)
        {
            if (track == null)
            {
                throw new ArgumentNullException(nameof(track));
            }

            var payload = new PlayPayload(VoiceChannel.GuildId, track, false);
            await _lavaSocket.SendAsync(payload)
            .ConfigureAwait(false);

            Track       = track;
            PlayerState = PlayerState.Playing;
        }
コード例 #2
0
        /// <inheritdoc />
        public async ValueTask DisposeAsync()
        {
            await StopAsync()
            .ConfigureAwait(false);

            var payload = new DestroyPayload(VoiceChannel.GuildId);
            await _lavaSocket.SendAsync(payload)
            .ConfigureAwait(false);

            GC.SuppressFinalize(this);

            Queue.Clear();
            Queue        = default;
            Track        = null;
            VoiceChannel = null;
            PlayerState  = PlayerState.Disconnected;
        }
コード例 #3
0
ファイル: LavaPlayer.cs プロジェクト: svr333/Victoria
        /// <summary>
        /// Plays the specified track with provided arguments.
        /// </summary>
        /// <param name="playArgsAction"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Throws when <paramref name="playArgsAction"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Throws when the volume is out of range.</exception>
        public async Task PlayAsync(Action <PlayArgs> playArgsAction)
        {
            var playArgs = new PlayArgs();

            playArgsAction.Invoke(playArgs);

            Track       = playArgs.Track ?? throw new NullReferenceException(nameof(playArgs));
            PlayerState = playArgs.ShouldPause ? PlayerState.Paused : PlayerState.Playing;

            if (playArgs.Volume < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(playArgs.Volume),
                                                      "Volume must be greater than or equal to 0.");
            }

            if (playArgs.Volume > 1000)
            {
                throw new ArgumentOutOfRangeException(nameof(playArgs.Volume),
                                                      "Volume must be less than or equal to 1000.");
            }

            Volume = playArgs.Volume;
            await _lavaSocket.SendAsync(new PlayPayload(VoiceChannel.GuildId, playArgs));
        }