Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add playback commands #36

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ch33kaboo
Copy link

@ch33kaboo ch33kaboo commented Mar 11, 2024

This is the implementation of the feature request #35 (I opened few hours earlier).
Adding commands to the plugin is useful because the user can control their playback without touching the mouse, they can use the command palette or assign hotkeys (keyboard shortcuts) to the commands.
Here is a breakdown of the changes:

  • I defined this.addCommand({}) for three different commands (play next track, play previous track, and toggle play/pause)
  • to play next track and previous track, I just used this.next() and this.previous() respectively
  • to play/pause current track, I added a variable to store the track state (whether it is playing or paused) and then make the command toggle the state

I tested the changes and they all work fine
image

main.ts Outdated
id: "Play/Pause",
name: "Play/Pause current track",
callback: () => {
if (isTrackPlaying) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of introducing a new variable, you should be able to use:

if(this.localPlayerStateObservable.getValue().playerState === PLAYER_STATE.PLAYING)

in the previous commit, I was introducing a new global variable to know the state of the current track (whether it is playing or paused) but it seems like there is another way to do it without adding a new variable
@ch33kaboo
Copy link
Author

hello @andrewmcgivery , I didn't know there was a simple way to know if the track is playing or not and that's why I introduced a new variable.
Anyway, I fixed the code by using if(this.localPlayerStateObservable.getValue().playerState === PLAYER_STATE.PLAYING) as you mentioned, I tested it and it works all fine. 👍👍

@ch33kaboo
Copy link
Author

ping @andrewmcgivery 😄
can you look into this please, or test it and merge it, because I think it is really usefull and I would like to see it merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants