Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Trying to have global playpause key on mpv ...

  1. #1
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan
    Beans
    2,211
    Distro
    Ubuntu 18.04 Bionic Beaver

    Trying to have global playpause key on mpv ...

    ... and not getting there as yet

    if the player is visible on desktop the "p" key will do that but i want this as a global key

    as I have in all my other players xmms / moc / winamp / foobar and all flawlessly recorded in ~/.config/openbox/lxde-rc.xml . I use LXDE as DE.

    mpv seems to be rigged up differently

    ANY ideas?

    thanx shan


    Code:
    <keyboard>
    #xmms
    
    
        <keybind key="A-x">
          <action name="Execute">
              <command>xmms -t</command>
              </action>
        </keybind>
    
    
    #moc
    
    <!-- Keybindings for mocp play/pause -->
      <keybind key="A-m"><action name="Execute"><command>mocp -G</command></action></keybind>
    
    
    <!-- Keybindings for mocp previous -->
      <keybind key="A-C-r"><action name="Execute"><command>mocp -r </command></action></keybind>
    
    
    <!-- Keybindings for mocp next -->
      <keybind key="A-C-f"><action name="Execute"><command>mocp -f </command></action></keybind>
      
    
    
      
    #mpv playpause
    
    
      <keybind key="A-z">
          <action name="Execute">
              <command>"mpv --pause"
              </command></action>
        </keybind>
    
    
    
    
      
      
    #winamp 
    
    
      <keybind key="A-b">
          <action name="Execute">
              <command>wine ~/.wine/dosdevices/c:/"Program Files (x86)"/Winamp/CLEveR.exe playpause</command></action>
        </keybind>
        
      <keybind key="C-7">
          <action name="Execute">
              <command>wine ~/.wine/dosdevices/c:/"Program Files (x86)"/Winamp/CLEveR.exe voldn</command></action>
        </keybind>   
        
      <keybind key="C-8">
          <action name="Execute">
              <command>wine ~/.wine/dosdevices/c:/"Program Files (x86)"/Winamp/CLEveR.exe volup</command></action>
        </keybind>      
    
    
    #foobar
    
    
    <keybind key="A-f"><action name="Execute"><command>wine ~/.wine/dosdevices/c:/"Program Files (x86)"/foobar2000/foobar2000.exe /playpause</command></action></keybind>
    
    
    <keybind key="C-0"><action name="Execute"><command>wine /home/shan/.wine/dosdevices/c:/"Program Files (x86)"/foobar2000/foobar2000.exe /command:Up</command></action></keybind>
    
    
    <keybind key="C-9"><action name="Execute"><command>wine /home/shan/.wine/dosdevices/c:/"Program Files (x86)"/foobar2000/foobar2000.exe /command:Down</command></action></keybind>
    
    </keyboard>
    Last edited by shantiq; February 8th, 2020 at 11:47 AM.
    Linux is Latin for off-the-beaten-track
    what I like MOST about our Ubuntu ... The Community
    Playing with Slackware too now ...
    ShanArt

  2. #2
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    15,056
    Distro
    Kubuntu 20.04 Focal Fossa

    Re: Trying to have global playpause key on mpv ...

    I'm not sure I understand the question. I've always used the space bar to start and pause playback in mpv and its predecessor mplayer. Works with mpv with SMPlayer as the front-end, too. The man page for mpv shows "p" and the space bar as synonyms.

    I use SMPlayer and have it configured to pause playback when the application is minimized. If I use mpv alone from the command prompt, the video continues to play when minimized, but if I hit the space bar in the window that spawned mpv, the playback is paused. If the focus is in any other window, the keystroke is ignored, and playback continues. Are you looking for a keystroke sequence that works in this case?
    Last edited by SeijiSensei; February 3rd, 2020 at 05:06 PM.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  3. #3
    Join Date
    Jun 2007
    Beans
    17,315

    Re: Trying to have global playpause key on mpv ...

    What you're doing clearly won't work, the command mpv --pause does nothing without mpv being opened on a file to pause on
    mpv /path/to/file --pause

    Now there could be ways, possibly a lua script if 'window unfocused' is a property that can be observed
    (there is a lua script provided with most mpv packages that does 'pause when minimize' (/usr/share/doc/mpv/tools/lua
    Or maybe some 3rd party app that could pass pause to the already open mpv window.

    There is a roundabout way though may have unintended consequences...

    Code:
    mkfifo /home/username/mpvfifo
    Add line to .config/mpv/mpv.conf
    Code:
    input-file=/home/username/mpvfifo
    Create an executable script in a bin folder in $PATH, lets say named cycle
    Code:
    #!/bin/bash
    echo 'cycle pause' > /home/username/mpvfifo
    Bind a system key with command of cycle
    (- here in Ubuntu you can't bind a single key in keyboard > shortcuts > custom, so tested with ctrl+a, works fine on a foused or unfocused mpv window.

    Location of mpvfifo doesn't matter, 1st tried /tmp but that is removed on reboot..
    If you use mkfifo /tmp/mpvfifo then the fifo will be removed when rebooting. Then recreate by using the simple mkfifo /tmp/mpvfifo command on session start.

    Note: you can use both the pause with minimize lua script with above fifo, min. > paused, ctrl+a starts while keeping minimized, ect.
    You can have more than 1 fifo, just use different names, ex. mkfifo /home/doug/mpvfifo1

    There's a warning, Warning: option --input-file is deprecated and might be removed in the future (use --input-ipc-server).
    (- that method unclear to me atm..
    Last edited by mc4man; February 4th, 2020 at 08:19 AM. Reason: /tmp

  4. #4
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan
    Beans
    2,211
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Trying to have global playpause key on mpv ...

    thanx a lot mc4man will give it a whirl and report
    Linux is Latin for off-the-beaten-track
    what I like MOST about our Ubuntu ... The Community
    Playing with Slackware too now ...
    ShanArt

  5. #5
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan
    Beans
    2,211
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Trying to have global playpause key on mpv ...

    ok mc4man I tried to follow instructions but there is confusion for me on some points

    this is what i did

    Code:
    mkfifo /home/shan/mpvfifo
    
    
    ➋ added line to .config/mpv/mpv.conf
    Code:
    Code:
    input-file=/home/shan/mpvfifo

    ➌ created placed in home folder and made executable
    Code:
    #!/bin/bash
    echo 'cycle pause' > /home/shan/mpvfifo
    ➍ opened sudo leafpad ~/.config/openbox/lxde-rc.xml [i am in LXDE]
    and added
    Code:
    #mpv playpause
    
      <keybind key="A-z">
          <action name="Execute">
              <command>"'cycle pause'"
              </command></action>
        </keybind>
    and refreshed
    Code:
    openbox --reconfigure && lxpanelctl restart
    ➎ when i press A-z still getting Screenshot from 2020-02-07 08-10-01.png


    So no doubt misunderstood or placed items in wrong places

    Thank you for your help with this
    Mpv is still the best and it will be nice to have Global Key Command sorted too
    Last edited by shantiq; February 7th, 2020 at 09:17 AM.
    Linux is Latin for off-the-beaten-track
    what I like MOST about our Ubuntu ... The Community
    Playing with Slackware too now ...
    ShanArt

  6. #6
    Join Date
    Jun 2007
    Beans
    17,315

    Re: Trying to have global playpause key on mpv ...

    Quote Originally Posted by shantiq View Post
    ok mc4man I tried to follow instructions but there is confusion for me on some points

    this is what i did

    Code:
    mkfifo /home/shan/mpvfifo
    
    
    ➋ added line to .config/mpv/mpv.conf
    Code:
    Code:
    input-file=/home/shan/mpvfifo
    The above(#1 &#2) is correct but after you're veering off, 1st. a little, then a lot..

    Quote Originally Posted by shantiq View Post
    ➌ created placed in home folder and made executable
    Code:
    #!/bin/bash
    echo 'cycle pause' > /home/shan/mpvfifo
    This is correct though script is best placed in ~/bin. If not then your binding command needs to full path to the script.

    Quote Originally Posted by shantiq View Post
    ➍ opened sudo leafpad ~/.config/openbox/lxde-rc.xml [i am in LXDE]
    and added
    Code:
    #mpv playpause
    
      <keybind key="A-z">
          <action name="Execute">
              <command>"'cycle pause'"
              </command></action>
        </keybind>
    #4 is wrong. You want to bind to the script, not mpv. Think of it this way -
    When the binding calls the script it sends "cycle pause" to the fifo, mpv is 'monitoring' the fifo so it receives the command and reacts.

    So the binding command is the scriptname if in a bin folder or full path to the scriptname if just loose in home folder, i.e /home/shan/scriptname

  7. #7
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan
    Beans
    2,211
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Trying to have global playpause key on mpv ...

    yet again feeling admirative grateful and humbled ... and that is a good thing mc4man thanks for original explanation and clarification
    PS: funny that in such a sophisticated deep-level player that no thought has been given to easy Global Hotkeys
    xmms / moc / winamp / foobar all fairly easy even winamp requiring CLEveR.exe
    Audacious can be set from the GUI


    ➊ moved cycle script so now in : /home/shan/bin/cycle
    ➋ changed key to:

    Code:
    #mpv playpause
    
      <keybind key="A-z">
          <action name="Execute">
              <command>"/home/shan/bin/cycle"
              </command></action>
        </keybind>


    and perfect and incredibly quick puter response ...so thanx
    Could create cycle 1 cycle2 for other commands but fine for now


    ========

    Now I can sit back feet away from my computer with a small keyboard ... punch "Alt-z" and have my beloved mpv on remote control QED and play a mixture of YT videos audio and hard drive files ...

    Code:
    mpv --no-video --no-resume-playback --loop-playlist  alfred\ panou\ AEC.m3u
    Warning: option --input-file is deprecated and might be removed in the future (use --input-ipc-server).
    
    Playing: https://www.youtube.com/watch?v=UvnsbqZthFU  #AEC Reese and the Smooth Ones, Pt. 1
     (+) Audio --aid=1 --alang=eng (*) (opus 2ch 48000Hz)
    AO: [pulse] 48000Hz stereo 2ch float
    Title: Reese and the Smooth Ones, Pt. 1
    A: 00:00:02 / 00:19:57 (0%) Cache: 34s/1MB
    
    Playing: /home/shan/Music/Elissa - Ila Kol Elli Bihebbouni [2018]/kol.cue
         Video --vid=1 [P] (png 1600x1456)
     (+) Audio --aid=1 (flac 2ch 48000Hz)
    File tags:
     Artist: Elissa
     Album: Ila Kol Elli Bihebbouni
     Date: 2018
     Genre: Lebanese Pop
    Title: kol.cue
    A: 00:00:15 / 01:13:24 (0%)
    
    Playing: https://www.youtube.com/playlist?list=PLWMfoGAL4WggNmEjvB5hBohvbV7sJXtIr # Catherine Derain
    A: 00:00:15 / 01:13:24 (0%)
    
    Playing: https://youtu.be/HhlRuFOZ_os
    A: 00:00:15 / 01:13:24 (0%)
     (+) Audio --aid=1 --alang=eng (*) (opus 2ch 48000Hz)
    Title: Être femme en son temps
    (Paused) A: 00:00:02 / 00:02:32 (1%) Cache: 149s/6MB
    Last edited by shantiq; February 8th, 2020 at 01:01 PM.
    Linux is Latin for off-the-beaten-track
    what I like MOST about our Ubuntu ... The Community
    Playing with Slackware too now ...
    ShanArt

  8. #8
    Join Date
    Jun 2007
    Beans
    17,315

    Re: Trying to have global playpause key on mpv ...

    There's a warning, Warning: option --input-file is deprecated and might be removed in the future (use --input-ipc-server).
    (- that method unclear to me atm..
    So at some point they'll likely remove the --input-file option. The now preferred is pretty straightforward.
    Typical usage would be to open a fresh terminal & send command(s) to open mpv instance but for this use (a binding), a script is way to go like before.

    To do:
    This uses socat so 1st.
    Code:
    sudo apt install socat
    Then add this line to .config/mpv/mpv.conf, remove input-file= line if there.
    Code:
    input-ipc-server=/tmp/mpvsocket
    Create an executable script in $PATH (like ~/bin)
    Code:
    #!/bin/bash
    echo '{"command": ["cycle", "pause"]}' | socat - /tmp/mpvsocket
    Then create a binding to either scriptname or /path/to/scriptname.
    Last edited by mc4man; February 10th, 2020 at 12:30 AM. Reason: spell

  9. #9
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan
    Beans
    2,211
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Trying to have global playpause key on mpv ...

    Thanx mc4 updated
    means the pesky message disappears



    very neat ... had read around socat but could not make sense of it ...


    now >>
    Code:
     mpv --no-video --no-resume-playback --loop-playlist  alfred\ panou\ AEC.m3u
    
    Playing: https://www.youtube.com/watch?v=1Mp8yqVDAXo #Smiling Faces Sometimes - The Undisputed Truth
     (+) Audio --aid=1 --alang=eng (*) (opus 2ch 48000Hz)
    AO: [pulse] 48000Hz stereo 2ch float
    Title: The Undisputed Truth - Smiling Faces Sometimes (HD)
    (Paused) A: 00:00:02 / 00:03:15 (1%) Cache: 191s/7MB

    EDIT: there is a kink tho with input-ipc-server=/tmp/mpvsocket so for the time being i reverted to input-file=/home/YOURNAME/mpvfifo

    Route 1 mpvfifo allows for one instance of mpv to be paused start other instance in a different tab or terminal window say for a film ; exit that then unpause the earlier mpv instance

    Route 2 socat fails to do that; ie it switches to most recent then "forgets" earlier instance

    So mpvfifo trumps socat so far

    Since I do not understand what happens behind the scenes here I simply explain it as a user and mpvfifo route works better therefore
    Hope this is explained well enough; I do not think I am mistaken here
    PS: also it seems reaction time on mpvfifo route even faster : Instant


    shan
    Last edited by shantiq; February 11th, 2020 at 07:59 AM. Reason: interesting issue
    Linux is Latin for off-the-beaten-track
    what I like MOST about our Ubuntu ... The Community
    Playing with Slackware too now ...
    ShanArt

  10. #10
    Join Date
    Jul 2009
    Location
    Hippiesoldierstan
    Beans
    2,211
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Trying to have global playpause key on mpv ...

    Now socat the only route and yes it definitely remembers only ONE instance of mpv running ... but that is fine
    Last edited by shantiq; April 29th, 2020 at 12:19 PM.
    Linux is Latin for off-the-beaten-track
    what I like MOST about our Ubuntu ... The Community
    Playing with Slackware too now ...
    ShanArt

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •