17
submitted 19 hours ago by AstroLightz@lemmy.world to c/linux@lemmy.ml

I'm making a Python script to play music through VLC and I wanted to add a way to control audio playback of VLC, like pause/play, next/previous, etc.

I know I can change shuffle mode before launching VLC with the --random and --no-random arguments. However, is there a way to change playback settings through the Linux terminal while VLC is running?

you are viewing a single comment's thread
view the rest of the comments
[-] Maxy@lemmy.blahaj.zone 18 points 19 hours ago

VLC appears to support MPRIS, so commands like

$ playerctl play-pause
$ playerctl next
$ playerctl previous

Should be able to control it. See the Relevant arch wiki page for more info.

VLC also appears to have a TUI interface. Check out the VLC wiki

[-] flameleaf@lemmy.ml 5 points 8 hours ago

VLC also appears to have a TUI interface. Check out the VLC wiki

There's also a CLI interface accessible through cvlc

[-] AstroLightz@lemmy.world 2 points 16 hours ago

Thank you so much! One more thing: would there be a way to check if the user has playerctl installed on their system? Or is there a Python package like it?

[-] floquant@lemmy.dbzer0.com 1 points 13 minutes ago* (last edited 5 minutes ago)

You can test if a command exists in several ways, but the most portable one should be using command -v which is POSIX.

if command -v playerctl &> /dev/null
  # do things
else
  # warn and exit (or prompt for installation)
end
[-] WronglyCommute@programming.dev 1 points 2 hours ago

You could always run whereis playerctl and parse the output with awk or sed

[-] floquant@lemmy.dbzer0.com 1 points 8 minutes ago

whereis is not a Bash built-in so it may itself not be installed, plus it exits 0 and returns output even on no match requiring additional logic/processing. which or command are more robust choices for this usecase

[-] Maxy@lemmy.blahaj.zone 1 points 4 hours ago

That depends on your distro. On Debian/ubuntu(-based) distro's, you can try apt list --installed playerctl, which will output nothing if the package isn't yet installed, or the package name with version info if it is installed. To install it, run sudo apt install playerctl

On arch(-based) distro's, you can try pacman -Qi playerctl, which should return an error if there is no such package installed, or several lines of info if it is installed. To install it, run sudo pacman -S playerctl, ideally after running a full system upgrade with sudo pacman -Syu

[-] floquant@lemmy.dbzer0.com 1 points 6 minutes ago

Testing if the current shell can execute something does not require looking at the installed packages, there are portable ways to do that

[-] felsiq@piefed.zip 1 points 9 hours ago

If you don’t want a playerctl dependency you can use a dbus library to check for mpris players manually, though it’s a little less readable

[-] nfms@lemmy.ml 1 points 2 hours ago

https://wiki.archlinux.org/title/MPRIS

In section 2.3 it explains how to use D-Bus and I think OP should use it instead

load more comments (-1 replies)
this post was submitted on 06 Mar 2026
17 points (100.0% liked)

Linux

63547 readers
238 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 6 years ago
MODERATORS