KadoBOT / nvim-spotify

For productivity addicts who enjoy coding while listening to Spotify, and cannot lose their focus switching to the app to control their music.
GNU General Public License v3.0
182 stars 5 forks source link

Keybindings for Pause and Next not working #9

Closed maxmahlke closed 2 years ago

maxmahlke commented 2 years ago

I tried using the keybindings as given in the readme,

vim.api.nvim_set_keymap("n", "<leader>sp", "<Plug>(SpotifyPause)", , { silent = true }) -- Pause/Resume the current track

(btw notice the duplicated comma which has to be removed after "SpotifyPause)")

The keymap showed up in my which-key pop-up but did not pause the playback. My logfile did not show anything suspicious:

$ cat /tmp/nvim-spotify-plugin.log
Registering Plugin
getting devices
[[pop-os]]

I looked up the definition of SpotifyPause here:

https://github.com/KadoBOT/nvim-spotify/blob/5694a08f783b3288a4655a95fc737cc7b7c7a3c9/lua/nvim-spotify.lua#L131

After some experimenting, the following keymap works:

vim.api.nvim_set_keymap("n", "<leader>sp", ":call SpotifyPlayback('pause')<CR>",
                        {silent = true}) -- Pause/Resume the current track

So I had to remove the <c-u> part. AFAIK I have not changed the <c-u> binding, so I'm not sure why this worked.

KadoBOT commented 2 years ago

Hi @maxmahlke Thanks for raising this. I'll have a look, but I don't think the <c-u> part is the issue. Although one thing that I noticed is that the event which calls the playback status (to show the song in the statusline) can be called multiple times, for each instance of nvim you have open. In my case, some API calls were failing because that previous call consumed all the quota. So, for a sanity check, are you using the status:start() ?

Anyhow, I removed the <c-u> part from the code.

Another thing worth mentioning is that the <Plug>(SpotifyPause) keymap is set in the setup function. While the commands are set on the "register" phase. Which means that the latter is always available. So for sanity check number 2, did you call the setup function?

KadoBOT commented 2 years ago

Another thing you can try is skipping the song through the command line and seeing if it outputs an err. Sometimes spt give me some errors, when I select another device from the web player (or app):

❯ spt playback --next
Error: Spotify API error code 403: Player command failed: Restriction violated

(I believe they try to skip the song on a device that is not playing it, and thus the error)

Re-selecting the device seems to fix the issue:

❯ spt playback --next
契 Bad Habit - The Offspring
maxmahlke commented 2 years ago

I am using status:start(), even though I don't need it as I could not yet figure out how to add the playback status to lightline (I might add another issue about this at some point). So this did not break the keybinding. I also ran spt playback --next without any issue.

I pulled the latest commits and can confirm that the keybinding now works as expected after you removed the <c-u> bit. And btw, thanks for the previous-track function!

KadoBOT commented 2 years ago

Great news! I'll close this issue then. Feel free to open another one if needed.