Comments (10)
@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.
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.
And some things still seem to be wrong. As shown here
Even after calling dequeue after skipping myself.
from victoria.
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.
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.
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.
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.
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.
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.
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)
- LavaPlayer.VoiceChannel value doesn't change after moving to another channel HOT 1
- [Feature Request]: TrackEncoder HOT 8
- [Bug]: Expected end of string, but instead reached end of data. HOT 5
- [Bug]: https://yucked.github.io/Victoria/ Endpoint returns 404 HOT 1
- [Bug]: SkipAsync does not work for child classes of LavaTrack HOT 1
- [Bug]: Equalizer does not propagate updates? HOT 4
- [ BUG ] LavaPlayer.Vueue should be LavaPlayer.Queue and should be referred to something similar throughout the code HOT 4
- [ BUG ] .PlayAsync with PlayArgs always throws NullReferenceException HOT 1
- [ BUG ] GetPlayer&TryGetPlayer fails with KeyNotFoundException HOT 1
- [ BUG ] Some video make Victoria throw a silent exception, making all event not tigger anymore HOT 1
- [ BUG ] Some video make Victoria throw a silent exception, making all event not tigger anymore HOT 1
- How do I set up my services when using v6 version ? HOT 2
- [ BUG ] Tracks sometimes get stuck at the end of playback. HOT 5
- Can no longer add the lava node to IServiceCollection HOT 3
- [ BUG ] LavaTrackConvert fails to successfully
- [ BUG ] LavaTrackConverter fails to deserialize back to a LavaTrack
- [ BUG ] Victoria sending blank or slightly wrong payloads for the Stop and Resume functions to work expectedly HOT 1
- Error with LavaNode HOT 1
- [BUG] Failed to parse Websocket messages
- Int32 overflow when parsing track length after loading in a direct .mp3 stream HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from victoria.