How to tell is Totem is playing a video or not

1

I recently switched to DWM and I've been customizing it. I have xautolock setup to autolock my computer after 5 minutes. It gets annoying when I'm watching a movie using Totem. Is there a way to tell if Totem is currently playing a movie so I can edit my screen lock script to check for that? I don't just want it to assume that because Totem is running, it's not okay to lock the screen. It needs to be playing.

Kyle

Posted 2012-07-23T06:15:33.560

Reputation: 143

I was going to say "use D-Bus", but it turns out that Totem doesn't expose much of anything via D-Bus... – Ignacio Vazquez-Abrams – 2012-07-23T06:21:20.890

Answers

0

I found a post on Stackoverflow explainging how to enable a D-bus plugin for totem.

The Python script I came up with is ugly, but it does the job for making sure movies playing don't lock the screen:

import dbus


def totem_is_playing():
    try:
        T_SERVICE_NAME = "org.mpris.Totem"
        T_OBJECT_PATH = "/Player"
        T_INTERFACE = "org.freedesktop.MediaPlayer"

        session_bus= dbus.SessionBus()

        totem = session_bus.get_object(T_SERVICE_NAME, T_OBJECT_PATH)
        totem_mediaplayer = dbus.Interface(totem, dbus_interface=T_INTERFACE)

        status = totem_mediaplayer.GetStatus()
        if status[0] == 0:
            return True
        return False
    except dbus.exceptions.DBusException:
        return False

The plugin API can be explain via code review here: https://yayoutube.googlecode.com/svn-history/r50/trunk/totem/mpris/mpris.py

Kyle

Posted 2012-07-23T06:15:33.560

Reputation: 143

0

Couldn't you check for audio out on the sound card? Have it look at any output (headphones/speaker). I doubt if you'll ever be watching a movie silently...

Everett

Posted 2012-07-23T06:15:33.560

Reputation: 5 425

Yeah, but I don't mind if the computer locks while I play music. – Kyle – 2012-07-23T06:36:30.157

Then what you are attempting to do may be impossible. If you queue off of video, whenever the screen saver comes up, the computer won't lock. If you don't want to do this based off of totem running, you really don't have much else to work with... – Everett – 2012-07-23T06:41:56.770