Skip to content

Commit

Permalink
feat(Player): Add prioritize play method
Browse files Browse the repository at this point in the history
  • Loading branch information
hmes98318 committed Oct 6, 2024
1 parent 4830c92 commit a50bd15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/lib/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,29 @@ export default class Player {
this.playing = true;
}

/**
* Prioritizes playing a new track
* @param {Track | UnresolvedTrack} track - The track to prioritize
*/
public async prioritizePlay(track: Track | UnresolvedTrack, requester: User) {
track.setRequester(requester);
const inserted = this.queue.insert(0, track);

if (!inserted) {
throw new Error('Failed to insert track at the front of the queue');
}


if (this.playing && this.current) {
this.queue.add(this.current);
return await this.skip();
}
else {
await this.play();
return true;
}
}

/**
* Pause or unpause the player
* @param {Boolean} [state=true] - Whether to pause or unpause the player
Expand Down
5 changes: 5 additions & 0 deletions typings/src/lib/Player.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export default class Player {
* @param {Boolean} [options.noReplace] - Whether to ignore operation if a track is already playing or paused
*/
play(options?: PlayOptions): Promise<void>;
/**
* Prioritizes playing a new track
* @param {Track | UnresolvedTrack} track - The track to prioritize
*/
prioritizePlay(track: Track | UnresolvedTrack, requester: User): Promise<boolean>;
/**
* Pause or unpause the player
* @param {Boolean} [state=true] - Whether to pause or unpause the player
Expand Down

0 comments on commit a50bd15

Please sign in to comment.