Giter VIP home page Giter VIP logo

Comments (10)

Yucked avatar Yucked commented on August 27, 2024 1

@MonstahGames Yeah that's the issue that I'm having as well. I add x thing and it breaks y for some reason. Part of my wants to change the Queue to a HashSet but there is no guarantee of tracks being in correct order.

from victoria.

Yucked avatar Yucked commented on August 27, 2024 1

So, I've fixed the skip function by changing couple of things around and making queue stuff a lot easier to understand. I've tested it with 3 tracks and it seems to be working as expected. Further testing might be required or perhaps intense testing but it should get the basic work done.

from victoria.

Daniele122898 avatar Daniele122898 commented on August 27, 2024

And some things still seem to be wrong. As shown here

Even after calling dequeue after skipping myself.

from victoria.

Daniele122898 avatar Daniele122898 commented on August 27, 2024

I can manually remove the song but the title etc of current track are the one from the old one... idk whats up

from victoria.

Yucked avatar Yucked commented on August 27, 2024

You make a good point there. It wouldn't work for the very first track since the queue is empty.
But this shouldn't brick LavaNode#LeaveAsync since:

// LavaPlayer#Dispose
        private void Dispose()
        {
            _lavaSocket.SendPayload(new DestroyPayload(Guild.Id));
            VoiceChannel = null;
            TextChannel = null;
            CurrentTrack = null;
            Position = TimeSpan.MinValue;
            LastUpdate = DateTime.Now;
            Queue.Clear();
            Queue = null;
            Volatile.Write(ref IsDisposed, true);
        }
// LavaPlayer#DisconnectAsync
        internal async Task DisconnectAsync()
        {
            await VoiceChannel.DisconnectAsync();
            Dispose();
        }

Which is called by LavaNode#LeaveAsync:

        /// <summary>
        /// Disconnects <see cref="LavaPlayer"/> from a guild and returns a bool.
        /// </summary>
        /// <param name="guildId">Guild Id.</param>
        /// <returns><c>bool</c></returns>
        public async Task<bool> LeaveAsync(ulong guildId)
        {
            if (!_players.TryGetValue(guildId, out var player))
                return false;
            await player.DisconnectAsync();
            return _players.TryRemove(guildId, out _);
        }

It isn't checking for whether the playing is connecting or not. It disconnects from the VoiceChannel and sets everything in LavaPlayer to null.

For the image itself, I don't know what is going wrong where.

from victoria.

Daniele122898 avatar Daniele122898 commented on August 27, 2024

In the image i implemented your skip function. I had 2 tracks in the queue. Calling skip by itself wouldnt remove anything from the queue and still show the old track as its player.currentTrack but play the new track. So i added some code that removes the newly playing track from the queue after skipping. Now whats weird is that the track that is playing after skip is indeed the new track, but when calling my now playing function which uses the player.currentTrack and its info it still displays the old track.

This is the skip function

public async Task<Embed> SkipAsync(ulong guildId, ulong userId)
        {
            var player = _lavaNode.GetPlayer(guildId);
            if(player?.CurrentTrack == null) return Utility.ResultFeedback(
                Utility.BlueInfoEmbed,
                Utility.MusicalNote,
                "Not playing anything currently.").Build();
            
            

            using (var soraContext = new SoraContext())
            {
                var guildDb = Utility.GetOrCreateGuild(guildId, soraContext);
                if (!guildDb.NeedVotes)
                {
                    var track = player.CurrentTrack;
					// i use the skip here
                    player.Skip();
					//remove the track from the queue myself as it didnt when i tested.
                    if(player.CurrentTrack != null)
                        player.Dequeue(player.CurrentTrack);
                    return Utility.ResultFeedback(
                        Utility.BlueInfoEmbed,
                        Utility.MusicalNote,
                        $"Skipped: {track.Title}")
                        .WithUrl(track.Uri.ToString()).Build();
                }
            }

            [...] // unnecessary to show here
        }

The now playing command has some fancy additions that aren't needed but the important part is that i use player.currenttrack.title etc after the skip but it shows the wrong info as you can see in the image. It should display the guilty crown OST that was after it in the queue.

public Embed NowPlaying(ulong guildId)
        {
            var player = _lavaNode.GetPlayer(guildId);
            if(player?.CurrentTrack == null) return Utility.ResultFeedback(
                Utility.BlueInfoEmbed,
                Utility.MusicalNote,
                "Not playing anything currently.").Build();

            if (player.CurrentTrack.IsStream)
            {
                return Utility.ResultFeedback(
                    Utility.BlueInfoEmbed,
                    Utility.MusicalNote,
                    "Cannot display more info of a stream").Build();
            }

            double percentageDone = (100.0 / player.CurrentTrack.Length.TotalSeconds) *
                                    player.Position.TotalSeconds;

            int rounded = (int) Math.Floor(percentageDone / 10);
            string progress = "";
            for (int i = 0; i < 10; i++)
            {
                if (i == rounded) {
                    progress += " :red_circle: ";
                    continue;
                }
                progress += "";
            }

            return Utility.ResultFeedback(
                Utility.BlueInfoEmbed,
                Utility.MusicalNote,
                $"Currently playing by {player.CurrentTrack.Author}")
                .WithDescription($"**[{player.CurrentTrack.Title}]({player.CurrentTrack.Uri})**")
                .AddField(x =>
                {
                    x.IsInline = false;
                    x.Name = "Progress";
                    x.Value =
                        $"[{player.Position.ToString(@"mm\:ss")}] {progress} [{player.CurrentTrack.Length.ToString(@"mm\:ss")}]";
                })
                .Build();    
        }

from victoria.

Yucked avatar Yucked commented on August 27, 2024

Yeah so for the past few hours I've been trying to write a skip function without much success.

        public void Skip()
        {
            if (!IsConnected)
                throw new InvalidOperationException("Either this player isn't connected or connection isn't valid.");
            var find = Queue.Find(CurrentTrack);
            LavaTrack track;
            if (find?.Value is null)
            {
                Stop();
                track = Queue.First?.Value;
            }
            else
            {
                Queue.RemoveFirst();
                track = Queue.First?.Value;
            }

            if (track is null)
                return;
            Play(track);
        }

from victoria.

ThybeVB avatar ThybeVB commented on August 27, 2024

I didn't want to have to start a new issue so i'll just it here, It's not a big problem on my end, but when you call the Skip function on the last song it will replay that last song. Is this expected?

from victoria.

Yucked avatar Yucked commented on August 27, 2024

So I was able to fix the skip thing with ConcurrentQueue but that makes Dequeue(LavaTrack/s) things useless coz ConcurrentQueue de-queues the first object from the queue.

If you guys are fine with it, then I'll go ahead replace the default queue stuff.

Other option is to build a default collection based on LinkedList if you want to keep the same functionality. Something like:

public class LavaQueue<T> : LinkedList<T> {}

and somehow sync ConcurrentQueue with LinkedList, so on and so forth.

from victoria.

Daniele122898 avatar Daniele122898 commented on August 27, 2024

i mean all u will ever need is to pop the first item from a queue. thats what a queue is for. no need to search a specific track. skipping a song is essential for any music player so having that working is way more important ^^.

from victoria.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.