change some structure again

fixed Rewind not restarting song https://cloud.tomatentum.net/apps/deck/#/board/19/card/241

added song queue prepend position https://cloud.tomatentum.net/apps/deck/#/board/19/card/224
This commit is contained in:
Tim Müller 2022-03-28 20:46:48 +02:00
parent d432575da6
commit b23d1aa71c
19 changed files with 34 additions and 8 deletions

@ -13,6 +13,7 @@ using TomatenMusic.Music;
using TomatenMusic.Music.Entitites; using TomatenMusic.Music.Entitites;
using TomatenMusic.Util; using TomatenMusic.Util;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Commands namespace TomatenMusic.Commands
{ {
@ -250,7 +251,7 @@ namespace TomatenMusic.Commands
_ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(player.State == PlayerState.NotPlaying ? "Now Playing:" : "Added to Queue") _ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(player.State == PlayerState.NotPlaying ? "Now Playing:" : "Added to Queue")
.AddEmbed(Common.AsEmbed(track, player.PlayerQueue.LoopType, player.State == PlayerState.NotPlaying ? 0 : player.PlayerQueue.Queue.Count + 1))); .AddEmbed(Common.AsEmbed(track, player.PlayerQueue.LoopType, player.State == PlayerState.NotPlaying ? 0 : player.PlayerQueue.Queue.Count + 1)));
await player.PlayAsync(response.Track); await player.PlayItemAsync(response.Track);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -317,7 +318,7 @@ namespace TomatenMusic.Commands
_ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(player.State == PlayerState.NotPlaying ? "Now Playing:" : "Added to Queue") _ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(player.State == PlayerState.NotPlaying ? "Now Playing:" : "Added to Queue")
.AddEmbed(Common.AsEmbed(track, player.PlayerQueue.LoopType, player.State == PlayerState.NotPlaying ? 0 : player.PlayerQueue.Queue.Count + 1))); .AddEmbed(Common.AsEmbed(track, player.PlayerQueue.LoopType, player.State == PlayerState.NotPlaying ? 0 : player.PlayerQueue.Queue.Count + 1)));
await player.PlayAsync(response.Track); await player.PlayItemAsync(response.Track);
sw.Stop(); sw.Stop();
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute."); _logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");

@ -9,6 +9,7 @@ using Lavalink4NET.Player;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Lavalink4NET; using Lavalink4NET;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Music.Entitites namespace TomatenMusic.Music.Entitites
{ {

@ -6,6 +6,7 @@ using TomatenMusic.Util;
using DSharpPlus.Entities; using DSharpPlus.Entities;
using Lavalink4NET.Player; using Lavalink4NET.Player;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Music.Entitites namespace TomatenMusic.Music.Entitites
{ {

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using TomatenMusic.Music; using TomatenMusic.Music;
namespace TomatenMusicCore.Music namespace TomatenMusicCore.Music.Entities
{ {
public interface IPlayableItem public interface IPlayableItem
{ {

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Music.Entitites namespace TomatenMusic.Music.Entitites
{ {
@ -43,6 +44,8 @@ namespace TomatenMusic.Music.Entitites
if (!player.PlayerQueue.Queue.Any()) if (!player.PlayerQueue.Queue.Any())
player.PlayerQueue.CurrentPlaylist = this; player.PlayerQueue.CurrentPlaylist = this;
player.PlayerQueue.Queue = new Queue<TomatenMusicTrack>(player.PlayerQueue.Queue.Prepend(new TomatenMusicTrack(player.PlayerQueue.LastTrack.WithPosition(player.TrackPosition))));
Queue<TomatenMusicTrack> reversedTracks = new Queue<TomatenMusicTrack>(Tracks); Queue<TomatenMusicTrack> reversedTracks = new Queue<TomatenMusicTrack>(Tracks);
TomatenMusicTrack track = reversedTracks.Dequeue(); TomatenMusicTrack track = reversedTracks.Dequeue();

@ -7,17 +7,18 @@ using System.Threading.Tasks;
using TomatenMusic.Music; using TomatenMusic.Music;
using TomatenMusic.Prompt.Implementation; using TomatenMusic.Prompt.Implementation;
namespace TomatenMusicCore.Music namespace TomatenMusicCore.Music.Entities
{ {
public class TomatenMusicTrack : LavalinkTrack, IPlayableItem public class TomatenMusicTrack : LavalinkTrack, IPlayableItem
{ {
public override TimeSpan Position { get; }
public TomatenMusicTrack public TomatenMusicTrack
(LavalinkTrack track) (LavalinkTrack track)
: base(track.Identifier, track.Author, track.Duration, track.IsLiveStream, track.IsSeekable, track.Source, track.Title, track.TrackIdentifier, track.Provider) : base(track.Identifier, track.Author, track.Duration, track.IsLiveStream, track.IsSeekable, track.Source, track.Title, track.TrackIdentifier, track.Provider)
{ {
Context = track.Context; Context = track.Context;
Position = track.Position;
} }
public string Title => base.Title; public string Title => base.Title;
@ -38,10 +39,12 @@ namespace TomatenMusicCore.Music
public async Task PlayNow(GuildPlayer player, TimeSpan? startTime = null, TimeSpan? endTime = null, bool withoutQueuePrepend = false) public async Task PlayNow(GuildPlayer player, TimeSpan? startTime = null, TimeSpan? endTime = null, bool withoutQueuePrepend = false)
{ {
if (!withoutQueuePrepend) if (!withoutQueuePrepend)
player.PlayerQueue.Queue = new Queue<TomatenMusicTrack>(player.PlayerQueue.Queue.Prepend(player.PlayerQueue.LastTrack)); player.PlayerQueue.Queue = new Queue<TomatenMusicTrack>(player.PlayerQueue.Queue.Prepend(new TomatenMusicTrack(player.PlayerQueue.LastTrack.WithPosition(player.TrackPosition))));
player.PlayerQueue.LastTrack = this; player.PlayerQueue.LastTrack = this;
await player.PlayAsync(this, startTime, endTime); await player.PlayAsync(this, startTime, endTime);
} }
} }
} }

@ -7,7 +7,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using TomatenMusic.Music; using TomatenMusic.Music;
namespace TomatenMusicCore.Music namespace TomatenMusicCore.Music.Entities
{ {
// //
// Summary: // Summary:
@ -550,6 +550,8 @@ namespace TomatenMusicCore.Music
{ {
Queue<TomatenMusicTrack> reversedTracks = new Queue<TomatenMusicTrack>(this); Queue<TomatenMusicTrack> reversedTracks = new Queue<TomatenMusicTrack>(this);
player.PlayerQueue.Queue = new Queue<TomatenMusicTrack>(player.PlayerQueue.Queue.Prepend(new TomatenMusicTrack(player.PlayerQueue.LastTrack.WithPosition(player.TrackPosition))));
TomatenMusicTrack track = reversedTracks.Dequeue(); TomatenMusicTrack track = reversedTracks.Dequeue();
player.PlayerQueue.LastTrack = track; player.PlayerQueue.LastTrack = track;
await player.PlayAsync(track, startTime, endTime); await player.PlayAsync(track, startTime, endTime);

@ -7,6 +7,7 @@ using Lavalink4NET.Player;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using TomatenMusic.Services; using TomatenMusic.Services;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Music.Entitites namespace TomatenMusic.Music.Entitites
{ {
@ -56,6 +57,9 @@ namespace TomatenMusic.Music.Entitites
if (!player.PlayerQueue.Queue.Any()) if (!player.PlayerQueue.Queue.Any())
player.PlayerQueue.CurrentPlaylist = this; player.PlayerQueue.CurrentPlaylist = this;
player.PlayerQueue.Queue = new Queue<TomatenMusicTrack>(player.PlayerQueue.Queue.Prepend(new TomatenMusicTrack(player.PlayerQueue.LastTrack.WithPosition(player.TrackPosition))));
Queue<TomatenMusicTrack> reversedTracks = new Queue<TomatenMusicTrack>(Tracks); Queue<TomatenMusicTrack> reversedTracks = new Queue<TomatenMusicTrack>(Tracks);
TomatenMusicTrack track = reversedTracks.Dequeue(); TomatenMusicTrack track = reversedTracks.Dequeue();

@ -16,6 +16,7 @@ using Lavalink4NET.Rest;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Lavalink4NET.Decoding; using Lavalink4NET.Decoding;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Music namespace TomatenMusic.Music
{ {
@ -87,7 +88,7 @@ namespace TomatenMusic.Music
{ {
EnsureNotDestroyed(); EnsureNotDestroyed();
EnsureConnected(); EnsureConnected();
if (Position.Position.Seconds < 4) if (Position.Position.Seconds > 5)
{ {
await ReplayAsync(); await ReplayAsync();
return; return;

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using TomatenMusic.Music.Entitites; using TomatenMusic.Music.Entitites;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Music namespace TomatenMusic.Music
{ {

@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging;
using Lavalink4NET.Player; using Lavalink4NET.Player;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Music namespace TomatenMusic.Music
{ {

@ -10,6 +10,7 @@ using TomatenMusic.Music;
using TomatenMusic.Music.Entitites; using TomatenMusic.Music.Entitites;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Prompt.Buttons namespace TomatenMusic.Prompt.Buttons
{ {

@ -13,6 +13,7 @@ using TomatenMusic.Prompt;
using TomatenMusic.Prompt.Model; using TomatenMusic.Prompt.Model;
using TomatenMusic.Util; using TomatenMusic.Util;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusicCore.Prompt.Implementation namespace TomatenMusicCore.Prompt.Implementation
{ {

@ -9,6 +9,7 @@ using TomatenMusic.Prompt.Buttons;
using TomatenMusic.Prompt.Model; using TomatenMusic.Prompt.Model;
using TomatenMusic.Util; using TomatenMusic.Util;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Prompt.Implementation namespace TomatenMusic.Prompt.Implementation
{ {

@ -12,6 +12,7 @@ using Microsoft.Extensions.Logging;
using TomatenMusic.Prompt.Buttons; using TomatenMusic.Prompt.Buttons;
using Lavalink4NET.Player; using Lavalink4NET.Player;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Prompt.Implementation namespace TomatenMusic.Prompt.Implementation
{ {

@ -13,6 +13,7 @@ using TomatenMusic.Music;
using System.Linq; using System.Linq;
using Lavalink4NET.Player; using Lavalink4NET.Player;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Prompt.Implementation namespace TomatenMusic.Prompt.Implementation
{ {

@ -13,6 +13,7 @@ using Lavalink4NET;
using Lavalink4NET.Player; using Lavalink4NET.Player;
using System.Runtime.Caching; using System.Runtime.Caching;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Services namespace TomatenMusic.Services
{ {

@ -9,6 +9,7 @@ using System.Web;
using TomatenMusic.Music.Entitites; using TomatenMusic.Music.Entitites;
using TomatenMusic.Services; using TomatenMusic.Services;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Music namespace TomatenMusic.Music
{ {

@ -13,6 +13,7 @@ using Lavalink4NET.Player;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Lavalink4NET; using Lavalink4NET;
using TomatenMusicCore.Music; using TomatenMusicCore.Music;
using TomatenMusicCore.Music.Entities;
namespace TomatenMusic.Services namespace TomatenMusic.Services
{ {