从Totem应用获取当前时间点

2 投票
1 回答
1837 浏览
提问于 2025-04-15 18:12

我想找到在运行中的Totem播放器里,媒体文件当前暂停或播放的确切时间。具体来说,我想要的内容可以通过Totem的python控制台获取(前提是插件存在并且已启用),使用以下命令:

>>> print totem_object.props.current_time
732616

我理解这个时间是以毫秒为单位的。

到目前为止:我之前从来没有使用过D-Bus,所以我正在学习D-Bus和python-dbus的文档。我还启动了D-Feet,发现了可以使用的org.gnome.Totem总线名称和/Factory对象,我可以使用org.freedesktop.DBus.Properties接口的方法。

我现在处于这个阶段:

>>> import dbus
>>> seb= dbus.SessionBus()
>>> t= seb.get_object('org.gnome.Totem', '/Factory')
>>> tif= dbus.Interface(t, 'org.freedesktop.DBus.Properties')
>>> tif.GetAll('')
dbus.Dictionary({}, signature=dbus.Signature('sv'))

我找不到合适的教程,所以任何帮助都将非常感激。

1 个回答

4

我现在在研究一个API,原因是我需要获取正在播放的路径或位置,结果碰巧看到了这个问题。

首先,你需要激活D-Bus服务插件(在编辑菜单中找到插件),这样就能使用org.mpris.Totem服务了。然后在/Player对象和org.freedesktop.MediaPlayer接口上,你可以用PositionGet()方法来获取当前播放的位置。

这个方法会返回你提到的totem.props.current_time

这里有一些代码示例:

import dbus

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)

print totem_mediaplayer.PositionGet()

至于整个org.gnome.Totem服务和Get/GetAll方法,我也不太明白它们的具体用途。看起来这些更多是和DBus本身有关,而不是特别针对Totem。

参考资料

  1. http://git.gnome.org/browse/totem/tree/src/plugins/dbusservice/dbusservice.py
  2. http://developer.gnome.org/totem/stable/TotemObject.html

撰写回答