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?

all 12 comments

sorted by: hot top controversial new old
[–] 20 points 8 months ago (9 children)

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

  • source
  • hideshow 9 child comments
  • [–] [S] 2 points 8 months ago (7 children)

    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?

  • source
  • parent
  • hideshow 7 child comments
  • [–] 3 points 8 months ago* (last edited 8 months 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
    
  • source
  • parent
  • [–] 2 points 8 months ago (1 child)

    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

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 8 months ago (1 child)

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

  • source
  • parent
  • hideshow 1 child comment
  • [–] 3 points 8 months 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

  • source
  • parent
  • [–] 2 points 8 months ago*

    I tinker with VLC using and... so far my "trick" is a bit dirty, namely I don't "control" it as much as I killall potential running instances then I start cvlc again with the right parameters. If you want continuity though you might not want that.

    Note also that if you plan to do scripting check mpv as it's a bit easier to tinker with IMHO.

    Python

    Check https://pypi.org/project/python-vlc/ then for Python bindings, that should give you the affordances you need.

  • source
  • [–] 0 points 8 months ago

    when you use the terminal, why use vlc when you can use ffmpeg?

  • source