0

我使用了一个使用 python-dbus 的小脚本和一个来自 org.kde.amarok /Player 的事件:

org.freedesktop.MediaPlayer.TrackChange

这是代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import dbus
import sys
import time
import gobject
from dbus.mainloop.glib import DBusGMainLoop

dbus_loop    = DBusGMainLoop(set_as_default=True)
dbus_session = dbus.SessionBus(mainloop=dbus_loop)
dbus_amarok  = None
dbus_psi     = None

try:
        dbus_amarok  = dbus_session.get_object('org.kde.amarok', '/Player')
        dbus_psi     = dbus_session.get_object('org.psi-im.Psi', '/Main')
except dbus.exceptions.DBusException:
        sys.stderr.write('Psi or Amarok not launched/reachable.\n')
        sys.stderr.flush()
        sys.exit(1)

def hdl_amarok_sig(sender=None):
        try:
                title  = sender.get('title').encode('utf-8')
                album  = sender.get('album').encode('utf-8')
                artist = sender.get('artist').encode('utf-8')
                play_msg = '♪ {} ({}) by {} ♪'.format(title, album, artist)
                print(play_msg)
                dbus_psi.setStatus('online', play_msg)
        except AttributeError:
                pass

dbus_amarok.connect_to_signal('TrackChange', hdl_amarok_sig)

loop = gobject.MainLoop()
loop.run()

然后例如:

♪ Með suð í eyrum (Með suð í eyrum við spilum endalaust) by Sigur Rós ♪
♪ Með suð í eyrum (Með suð í eyrum við spilum endalaust) by Sigur Rós ♪

这就是打印的内容,当然也是 psi 收到的内容。并且在网上找不到任何关于它的信息,我已经在 FreeBSD、Debian 不稳定和 Fedora 18 (KDE4) 上对其进行了测试。

4

1 回答 1

0

好的,这是来自 Amarok 的错误。使用克莱门汀播放器不要发送事件两次。错误报告。

于 2013-06-26T18:19:30.683 回答