Exemplo n.º 1
0
        /// <summary>
        ///     Plays the specified track with a custom start and end time.
        /// </summary>
        /// <param name="track">An instance of <see cref="LavaTrack" />.</param>
        /// <param name="startTime">Custom start time for track. Must be greater than 0.</param>
        /// <param name="endTime">Custom end time for track. Must be less than <see cref="LavaTrack.Duration" />.</param>
        /// <param name="noReplace">If true, this operation will be ignored if a track is already playing or paused.</param>
        /// <exception cref="ArgumentOutOfRangeException">Throws when start or end time are out of range.</exception>
        /// <exception cref="InvalidOperationException">Throws when star time is bigger than end time.</exception>
        public async Task PlayAsync(LavaTrack track, TimeSpan startTime, TimeSpan endTime, bool noReplace = false)
        {
            if (track == null)
            {
                throw new ArgumentNullException(nameof(track));
            }

            if (startTime.TotalMilliseconds < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(startTime), "Value must be greater than 0.");
            }

            if (endTime.TotalMilliseconds < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(endTime), "Value must be greater than 0.");
            }

            if (startTime <= endTime)
            {
                throw new InvalidOperationException($"{nameof(endTime)} must be greather than {nameof(startTime)}.");
            }

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

            Track       = track;
            PlayerState = PlayerState.Playing;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Plays the specified <paramref name="track"/>.
        /// </summary>
        /// <param name="track"><see cref="LavaTrack"/></param>
        /// <param name="noReplace">If set to true, this operation will be ignored if a track is already playing or paused.</param>
        public Task PlayAsync(LavaTrack track, bool noReplace = false)
        {
            IsPlaying    = true;
            CurrentTrack = track;
            var payload = new PlayPayload(VoiceChannel.GuildId, track.Hash, noReplace);

            return(_socketHelper.SendPayloadAsync(payload));
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Plays the specified <paramref name="track"/>.
        /// </summary>
        /// <param name="track"><see cref="ILavaTrack"/></param>
        /// <param name="noReplace">If set to true, this operation will be ignored if a track is already playing or paused.</param>
        public async Task PlayAsync(ILavaTrack track, bool noReplace = false)
        {
            this.IsPlaying    = true;
            this.CurrentTrack = track;
            this.LastUpdate   = DateTimeOffset.Now;
            if (!noReplace)
            {
                Volatile.Write(ref this._isPaused, false);
            }
            string trackHash = await GetTrackHash(track);

            var payload = new PlayPayload(this.VoiceChannel.GuildId, trackHash, noReplace);

            await this._socketHelper.SendPayloadAsync(payload);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Plays the specified <paramref name="track"/>.
        /// </summary>
        /// <param name="track"></param>
        /// <param name="startTime">Optional setting that determines the number of milliseconds to offset the track by.</param>
        /// <param name="stopTime">optional setting that determines at the number of milliseconds at which point the track should stop playing.</param>
        /// <param name="noReplace">If set to true, this operation will be ignored if a track is already playing or paused.</param>
        public Task PlayAsync(LavaTrack track, TimeSpan startTime, TimeSpan stopTime, bool noReplace = false)
        {
            if (startTime.TotalMilliseconds < 0 || stopTime.TotalMilliseconds < 0)
            {
                throw new InvalidOperationException("Start and stop must be greater than 0.");
            }

            if (startTime <= stopTime)
            {
                throw new InvalidOperationException("Stop time must be greater than start time.");
            }

            IsPlaying    = true;
            CurrentTrack = track;
            var payload = new PlayPayload(VoiceChannel.GuildId, track.Hash, startTime, stopTime, noReplace);

            return(_socketHelper.SendPayloadAsync(payload));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Plays the specified <paramref name="track"/>.
        /// </summary>
        /// <param name="track"></param>
        /// <param name="startTime">Optional setting that determines the number of milliseconds to offset the track by.</param>
        /// <param name="stopTime">optional setting that determines at the number of milliseconds at which point the track should stop playing.</param>
        /// <param name="noReplace">If set to true, this operation will be ignored if a track is already playing or paused.</param>
        public async Task PlayAsync(ILavaTrack track, TimeSpan startTime, TimeSpan stopTime, bool noReplace = false)
        {
            if (startTime.TotalMilliseconds < 0 || stopTime.TotalMilliseconds < 0)
            {
                throw new InvalidOperationException("Start and stop must be greater than 0.");
            }

            if (startTime <= stopTime)
            {
                throw new InvalidOperationException("Stop time must be greater than start time.");
            }

            this.IsPlaying    = true;
            this.CurrentTrack = track;
            if (!noReplace)
            {
                Volatile.Write(ref this._isPaused, false);
            }
            string trackHash = await GetTrackHash(track);

            var payload = new PlayPayload(this.VoiceChannel.GuildId, trackHash, startTime, stopTime, noReplace);

            await this._socketHelper.SendPayloadAsync(payload);
        }