3

rhythmbox-client --print-playing tells me the name of a song, regardless of whether it is actually playing. I simply need to know whether or not sound is currently being generated by rhythmbox (so that I know whether or not I want to pause it and later unpause it).

Update:

One ugly candidate answer:

I think rhythmbox really may be devoid of this basic interface.

But when I run pacmd list-sink-inputs which I gather queries the mixer about what is feeding, it still lists rhythmbox regardless of whether it's playing. However, it has a "state" row in the output, which is "RUNNING" or "CORKED" depending on whether the music is paused.

3
  • man rhytmbox-client suggests using --pause, which Pause playback if currently playing. I guess it will stay Paused if it already is, because there is a toggle: --play-pause Toggle play/pause mode.
    – waltinator
    Jul 1, 2016 at 17:46
  • That is correct, but not good enough for me. What I need to know is whether I should un-pause it again (--play) 25 minutes later. :)
    – CPBL
    Jul 1, 2016 at 17:54
  • I updated the question to suggest one approach, which seems to work (I've coded it in Python) for any player, though is rather indirect.
    – CPBL
    Jul 1, 2016 at 21:04

2 Answers 2

3

Media Player Remote Interfacing Specification (MPRIS)

You can use the MPRIS2 DBus interface, it is well established standard and implemented by almost all players.

The same standard that is used by Ubuntu Unity sound indicator to detect, show and control players. So your script will be generic and could work with any player you like.

Hint: Use D-Feet to explore it, d-feet is DBus monitor and can interact with DBus interfaces directly.

  • Pause

    gdbus call \
      --session \
      --dest org.mpris.MediaPlayer2.rhythmbox \
      --object-path /org/mpris/MediaPlayer2 \
      --method org.mpris.MediaPlayer2.Player.Pause
    
  • Pause/Resume

    gdbus call \
      --session \
      --dest org.mpris.MediaPlayer2.rhythmbox \
      --object-path /org/mpris/MediaPlayer2 \
      --method org.mpris.MediaPlayer2.Player.PlayPause
    
  • Check Status

    ~$ gdbus call \
         --session \ 
         --dest org.mpris.MediaPlayer2.rhythmbox \
         --object-path /org/mpris/MediaPlayer2 \
         --method org.freedesktop.DBus.Properties.Get \
             org.mpris.MediaPlayer2.Player PlaybackStatus
    (<'Playing'>,)
    
    ~$ gdbus call \
         --session \
         --dest org.mpris.MediaPlayer2.rhythmbox \
         --object-path /org/mpris/MediaPlayer2 \
         --method org.freedesktop.DBus.Properties.Get \
             org.mpris.MediaPlayer2.Player PlaybackStatus
    (<'Stopped'>,)
    
1
  • 1
    The cleanest option! was looking for this, you found it :) Jul 2, 2016 at 7:20
2

pacmd list-sink-inputs gives a list of all running players, so you don't even need to know which ones you're looking for in advance, and tells you which ones are playing / paused, etc. I wrote this for Python, but you could do a better job with awk or bash, I'm sure:

import commands,re
def linux_musicplayer_check_whether_playing():
    """
    Report which applications are currently sending 
    sound to the mixer, based on the output of the command:
       pacmd list-sink-inputs
    Also list those which are running/connected,
    but not currently sending sound.
    Returns a dict listing applications and a boolean playing state.

    This is very GNU/Linux specific! At least, it works on Ubuntu.  
    On other platforms, there may be direct ways for each application.

    For instance, under Ubuntu, you can ask banshee:

    'playing' in commands.getstatusoutput("banshee --query-current-state")[1])

    but there's nothing like this for rhythmbox.

    """

    found={}

    for cl in commands.getstatusoutput("pacmd list-sink-inputs |grep -e index: -e state: -e client:")[1].split('index:')[1:]:
        found[ re.findall('<(.*?)>', cl.split(':')[2])[0].lower() ]  =
                     'RUNNING' in cl.split(':')[1]
    return(found)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .