I have a music script I’m working on that uses VLC as its backend for playing music in the background. However, I was looking around the MPV CLI arguments, and there’s quite a few things there that would work for my script.

However, I have a few issues with MPV before implementing this addition:

  1. I don’t want a window to appear whenever I launch MPV.
  2. I want MPV to remember certain properties, like volume.
  3. I don’t want the CLI info displaying in the terminal. This would cause issues as now MPV will close when the terminal closes. I need this to run in the background, like VLC.

I’ve kinda managed to solve 1. by using --no-vid, but I haven’t figured out 2. or 3. yet. Does anyone know any tips, tricks, arguments, etc. to get the desired experience I want with MPV?

It’s a Python program, so I am using subprocess currently.

  • who@feddit.org
    link
    fedilink
    English
    arrow-up
    1
    ·
    10 hours ago

    I think mpd is better suited to your purpose than any GUI media player.

    Note that despite its network support, it can run and be controlled locally. Cantata uses it, for example.

  • Libb@piefed.social
    link
    fedilink
    English
    arrow-up
    7
    ·
    edit-2
    1 day ago

    Depends what operating system you’re using. I run Linux (Mint).
    And I use mpv a lot… it’s probably the application I’m the most stupidly fond of, as a user I find it amazingly good.

    I use it mostly through the Nemo file explorer (through its custom actions) as my video/music music player. But I also use it to listen to podcasts, using newsboat as my feed aggregator and yt-dlp to actually download/stream whatever multimedia content I want mpv to play. And, well, for everything else that contains video and/or audio.

    You can launch mpv with --no-video and no window will be displayed, say if you want to play only the audio from a video file. You can also launch it using the save-position-on-quit. I’ve mine set by default to yes (in mpv.conf), so it remembers position in whatever I play next time I play it, and on specific scripts/occasions it is set to ‘no’ (see example below).

    in my ~/.config.mpv/mpv.conf I have set volume=65 which is the level I want it to start with, while defining custom keyboard shortcuts and mouse scrolling buttons to change volume in the ~/.config.mpv/input.conf. I’ve never tried it but you might be able to add a volume parameter each time you launch mpv (maybe store the actual value in a hidden text file somewhere for it to load from, using a script?)

    Your 3, I’m not sure to understand what you want to do. But in order to keep mpv open after it’s done playing whatever, add this to your mpv.conf: keep-open=yes

    As an example, here is one of the ‘Nemo Actions’ I use to make mpv randomly play audio (even from video) from the folder I right-click on, without mpv opening any window. If you don’t know them already, custom Nemo Actions must be saved in ~/.local/share/nemo/some-file-name.nemo_action :

    [Nemo Action]  
    Active=true  
    Name=MPV shuffle NOVID  
    Comment=Play at random the content of selected folder into mpv AUDIO only, no position save 
    Exec=sh -c "mpv --no-video --save-position-on-quit=no --shuffle %F"  
    Icon-Name=multimedia-video-player  
    Selection=any  
    Extensions=any  
    

    The ‘exec’ part of that action uses standards mpv parameters next to Nemo’s own stuff.

    I also use the socat utility that lets me connect a series of tiny (they’re one-liners) custom shell scripts directly to mpv, using system-wide keyboard shortcuts. I’m really not an expert about any of that, I just learned to use it to get what I wanted out of it which is a … universal mpv remote-control.

    I don’t mean just the Play/Pause buttons but almost any of the controls I need with mpv.

    For example, I started using it to let me skip forward/backward a couple seconds and resume playback while I’m listening to audio notes, as I recently started using a pocket voice recorder. Which makes mpv great when I’m transcribing said notes. Not as good but quite close to one of those dedicated old-school foot pedal people into that kind of tech used to use in the 80s and 90s… Yep, don’t tell anyone but I’m that old that I remember them ;)

    Edit: I hope any of that can help you with your script.

    • AstroLightz@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      1
      arrow-down
      1
      ·
      1 day ago

      I’m targeting a Linux release

      Your 3, I’m not sure to understand what you want to do.

      I don’t want the active MPV file info in the terminal as if I CTRL+C, CTRL+D, or close the terminal, MPV will close too. So I want it to run as a background process (like how you can minimize VLC to the tray)

      I don’t know if using something like nohup mpv <some file> & would work. I guess I could use pkill mpv to close it then.

      I saw mpv has a --quiet option. What does that do?

  • sin_free_for_00_days@sopuli.xyz
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 day ago

    Must be some python hang up, because I regularly open a file from a terminal with mpv <options> <file> & exit and it doesn’t kill the mpv process when the terminal exits. As far as the volume, there’s this scrip that does what you want. I haven’t tried it out, but looks pretty basic.