I use i3wm as my window manager and I want to add a binding to play/pause, next, prev and stop VLC. However, unlike MPV, VLC doesn't have built-in CLI control when the VLC process is already running externally.
3 Answers
I found this lovely Reddit comment answering than need for play/pause, and through trial and error I found how to also stop/prev and next:
bindsym XF86AudioNext exec dbus-send --type=method_call \
--dest=org.mpris.MediaPlayer2.vlc \
/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
bindsym XF86AudioPrev exec dbus-send --type=method_call \
--dest=org.mpris.MediaPlayer2.vlc \
/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
bindsym XF86AudioPlay exec dbus-send --type=method_call \
--dest=org.mpris.MediaPlayer2.vlc \
/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
bindsym XF86AudioStop exec dbus-send --type=method_call \
--dest=org.mpris.MediaPlayer2.vlc \
/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop
EDIT: Using playerctl
like Antoine mentionned makes this more straightforward:
bindsym XF86AudioNext exec playerctl next
bindsym XF86AudioPrev exec playerctl previous
bindsym XF86AudioPlay exec playerctl play
bindsym XF86AudioStop exec playerctl pause
Would installing playerctl
work, alternatively?
-
This is even better than my solution ! Playerctl is labelled as "For players supporting the MPRIS D-Bus specification", which includes Spotify and VLC afaik. It works flawlessly and if far less barbaric than
dbus-send
lol. Though looking at the dbus syntax, playerctl is essetially doing the same thing as what I did. I will use playerctl instead, thank you :D Commented Dec 23, 2020 at 16:55 -
playerctl
seems to be a fine tool, however it's not available on Windows. Is there an alternative for this OS? Commented Jul 9, 2022 at 5:51
I'm using playerctl for controlling any playback settings
# Media player controls
bindsym XF86AudioPlay exec playerctl play-pause
#bindsym XF86AudioPause exec playerctl pause
bindsym XF86AudioNext exec playerctl next
bindsym XF86AudioPrev exec playerctl previous
But, if two applications are using audio at the same time, which one will respond to playerctl
, is unknown.