Comments (12)
Okay that was dumb on my part. Casting hierarchy doesn't work that way. So, yeah I will have to creator a CTOR for LavaTrack. I'll do it in next release hopefully in few hours.
from victoria.
This feature has been added in v5.1.9. You are now able to extend LavaTracks.
from victoria.
Hey, you can extend LavaTrack
or have a class that implements IQueueable
. For example:
public sealed class Request : IQueueable {
public LavaTrack Track { get; set; }
public ulong UserId { get; set; }
public IGuildUser User { get; set; }
}
...
if !(lavaPlayer.Queue.TryDequeue(out var queueable))
return;
var request = queueable as Request;
await lavaPlayer.PlayAsync(request.LavaTrack);
await ReplyAsync($"Now Playing: {request.LavaTrack.Title}\nRequested By: {request.User}");
from victoria.
I implemented IQueueable
, but when I queue the track, I lose the user I lose the user information. Same issue when getting the player’s current track. I’m not sure how I’d go on extending LavaTrack
from victoria.
Can you show me your code? I can help debug that issue and extending LavaTrack is simple.
public sealed class CustomTrack : LavaTrack {
}
Then instead of queueing LavaTrack you queue your CustomTrack. And cast IQueueable to CustomTrack when de-queueing from queue.
from victoria.
For the interface method heres my implementation:
public class RokiRequest : IQueueable
{
public LavaTrack Track { get; set; }
public IGuildUser User { get; set; }
}
and then I create a new request and add it to the queue.
var request = new RokiRequest {Track = result.Tracks.FirstOrDefault(), User = ctx.User as IGuildUser};
player.Queue.Enqueue(request);
this all works fine. But when I cannot get the custom request when doing getting the current track info
i.e.
var currTrack = player.Track;
the currTrack
would be a LavaTrack
from victoria.
Yeah then my previous reply should be of help.
from victoria.
So when I extend LavaTrack, would it be something like this?
public class RokiTrack : LavaTrack
{
public IGuildUser User { get; set; }
}
and then I do
var request = (RokiTrack) result.Tracks.First();
request.User = ctx.User as IGuildUser;
player.Queue.Enqueue(request);
correct?
from victoria.
Yes, that should be it.
from victoria.
I get this error when casting
System.InvalidCastException: Unable to cast object of type 'Victoria.LavaTrack' to type 'Roki.Modules.Music.Common.RokiTrack'.
from victoria.
Rip I know why. Okay so when you get tracks from search they are not RokiTrack. What you need to do is.
var track = Tracks.FirstOrDefault();
var RokiTrack = track as RokiTrack;
Try that and Lmk.
from victoria.
heres what I did
var track = result.Tracks.FirstOrDefault();
var request = track as RokiTrack;
if (request == null)
{
_log.Error("Error casting");
return;
}
the if statement is true every time
do I need to add the LavaTrack
properties in RokiTrack
? I dont think so right? since its extended from it.
Edit: what I've found out is that I would need to have a constructor in RokiTrack that sets the properties from LavaTrack, but I cannot since the set is private in LavaTrack
from victoria.
Related Issues (20)
- [Bug]: TrackStartEvent fires twice
- 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
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.