feat(Queue): queue#insert method
This commit is contained in:
parent
47039821ee
commit
67648af97b
2 changed files with 15 additions and 1 deletions
|
@ -498,6 +498,20 @@ class Queue<T = unknown> {
|
|||
return void this.skip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the given track to specified index
|
||||
* @param {Track} track The track to insert
|
||||
* @param {number} [index=0] The index where this track should be
|
||||
*/
|
||||
insert(track: Track, index = 0) {
|
||||
if (!track || !(track instanceof Track)) throw new TypeError("track must be the instance of Track");
|
||||
if (typeof index !== "number" || index < 0 || !Number.isFinite(index)) throw new Error(`Invalid index "${index}"`);
|
||||
|
||||
this.tracks.splice(index, 0, track);
|
||||
|
||||
this.player.emit("trackAdd", this, track);
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {object} PlayerTimestamp
|
||||
* @property {string} current The current progress
|
||||
|
|
Loading…
Reference in a new issue