Announcement

Collapse
No announcement yet.

How To Get Global Media Shortcuts in KDE

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How To Get Global Media Shortcuts in KDE

    One thing that bugged me about KDE was the lack of Global Media Shortcuts with music/video players. If you want a key for the Play/Pause, Next, Previous, or Stop functions you might have noticed they are assigned to Amarok by default. Well I wanted to be able to pause my music no matter if it was playing through Amarok, Banshee, Pithos, or any other player.

    One caveat at the moment, this only works with applications that support MPRIS or "Media Player Remote Interfacing Specification". A large amount of media applications already support this but if you aren't sure open your application and type this code in a terminal.
    Code:
    qdbus | grep org.mpris.MediaPlayer2 | sed 's/.*\.//'
    If you see your apps name after typing this command into the terminal then it will work. Make sure your application is open before you run this command.

    [Overview]
    The overview of my fix:
    Say I want to be able to set the Play/Pause button to work on any media player allowing me to play or pause the music. First create a script to send the the Play/Pause command to your applications.

    Here's my script for Play/Pause:
    Code:
    #!/bin/bash
    
    ## -- This script will imitate Gnome's Media Controls (Play/Pause, Next, Previous, Stop) -- ##
    ## -- It will assume you are using a media application that is compatible with MPRIS or  -- ##
    ## -- "Media Player Remote Interfacing Specification"                                    -- ##
    
    # Search for running media applications
    # and store into apps array
    apps=(`qdbus | grep org.mpris.MediaPlayer2 | sed 's/.*\.//'`)
    
    # For each application send the "PlayPause" command
    for app in "${apps[@]}"
      do    
            qdbus org.mpris.MediaPlayer2.$app /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
      done
    If you notice the actual command is specified at the end of the 2nd to last line. This "PlayPause" instructs the application to do what we want. But what if we want to add a Next Song key? Just copy this script and change the "PlayPause" to "Next". Pretty simple.

    Now all we have to do is assign this script to a global shortcut. In KDE go to System Settings > Shortcuts and Gestures > Custom Shortcuts. Right click in the white space and select New > Global Shortcut > Command URL. Name your Action whatever you like and now click the Trigger tab and assign your appropiate shorcut. Now click the Action tab and browse to your previously made script. Make sure your script is executable by quickly typing "chmod +x /home/USER/script". After you click Apply you should be able to control all supported media applications with your shortcut!

    #2
    VERY nice NarcT.

    Please do NOT be a stranger! I'm quite sure that any other suggestions you might make will be very well received!

    woodsmoke
    sigpic
    Love Thy Neighbor Baby!

    Comment


      #3
      Thanx man! You helped me very much!

      Comment


        #4
        Clementine media buttons

        Thanks to OP for pointing me in the right direction. I thought I would add my two cents for how to fix it in KDE 4.8 by putting the D-Bus commands as a new Custom Shortcut in SystemSettings -> Shortcuts and Gestures.

        Create a new custom shortcut by right clicking on the list, and then selecting New -> Global Shortcut -> D-Bus Command.

        Set the Trigger as your media key, assuming D-Bus is working correctly, the key should capture with no problem.

        Then in the Action tab, set 'org.mpris.MediaPlayer2.clementine' in the 'Remote Application' field. Set '/org/mpris/MediaPlayer2' in the Remote object field, Set the 'PlayPause', 'Previous', 'Next', 'Stop' method in the 'Function' field that matches the 'Trigger' button.

        Comment


          #5
          Use mpris-remote

          Sending the DBUS command from the panel is very nice, but if you want to change player then you must configure each button again.

          I suggest: "apt-get install mpris-remote".

          And then assing the keys to commands like this:
          • Stop: mpris-remote stop
          • Play/Pause: mpris-remote pause
          • Previous: mpris-remote prev
          • Next: mpris-remote next


          Now it should work with any MPRIS compliant player

          http://jaimealsilva.com/node/9

          Originally posted by hellslinger View Post
          Thanks to OP for pointing me in the right direction. I thought I would add my two cents for how to fix it in KDE 4.8 by putting the D-Bus commands as a new Custom Shortcut in SystemSettings -> Shortcuts and Gestures.

          Create a new custom shortcut by right clicking on the list, and then selecting New -> Global Shortcut -> D-Bus Command.

          Set the Trigger as your media key, assuming D-Bus is working correctly, the key should capture with no problem.

          Then in the Action tab, set 'org.mpris.MediaPlayer2.clementine' in the 'Remote Application' field. Set '/org/mpris/MediaPlayer2' in the Remote object field, Set the 'PlayPause', 'Previous', 'Next', 'Stop' method in the 'Function' field that matches the 'Trigger' button.
          Last edited by Guest; Nov 06, 2012, 01:04 PM.

          Comment


            #6
            Hello all,

            I tried jaimealsilva's method, which is very elegant, but unfortunately it doesn't work with the recent banshee (I needed this for banshee), since, if I understood correctly, banshee only implements mpris2 and the mpris-remote uses mpris1. So I went back to NarcT's initial method, which works like a charm.

            Thanks a lot guys, i'm staying on KDE (I'm coming from Gnome and currently trying to fill some wholes... )

            Comment


              #7
              Just want to thank U very much.

              OT: Where is the "thank" button guys? I really do not want to spam this thread with just a thank.

              Comment


                #8
                We don't have that feature here -- yet. Thanking someone isn't 'spam', so don't worry about it.
                Using Kubuntu Linux since March 23, 2007
                "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                Comment


                  #9
                  Sorry to necropost

                  I followed Hellslinger's suggestion regarding Clementine on my Netrunner 14.1 box running KDE SC 4.13.0. The only difference is I created the custom shortcut in SystemSettings > Shortcuts and Gestures > Custom Shortcuts > Preset Actions > Edit > New. I set the trigger to the Play/Pause button and the action to 'qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause.'

                  Originally posted by hellslinger View Post
                  Thanks to OP for pointing me in the right direction. I thought I would add my two cents for how to fix it in KDE 4.8 by putting the D-Bus commands as a new Custom Shortcut in SystemSettings -> Shortcuts and Gestures.

                  Create a new custom shortcut by right clicking on the list, and then selecting New -> Global Shortcut -> D-Bus Command.

                  Set the Trigger as your media key, assuming D-Bus is working correctly, the key should capture with no problem.

                  Then in the Action tab, set 'org.mpris.MediaPlayer2.clementine' in the 'Remote Application' field. Set '/org/mpris/MediaPlayer2' in the Remote object field, Set the 'PlayPause', 'Previous', 'Next', 'Stop' method in the 'Function' field that matches the 'Trigger' button.

                  Comment

                  Working...
                  X