2

我正在尝试通过 DBus 控制 omxplayer 的多个实例。这是我目前用来控制应用程序的代码:

QDBusConnection *m_dbus = new QDBusConnection(QDBusConnection::sessionBus());
m_dbus->connectToBus("/tmp/omxplayerdbus.root", "org.mpris.MediaPlayer2.omxplayer");
// ...
    QString dest = "org.mpris.MediaPlayer2.omxplayer";
    QString path = "/org/mpris/MediaPlayer2";
    QString interface = "org.mpris.MediaPlayer2.Player";
    QString name = "Action";
    QDBusMessage msg = QDBusMessage::createMethodCall(dest, path, interface, name);
    msg.setArguments(QList<QVariant>() << 16);
    m_dbus->send(msg);

/tmp/omxplayerdbus.root 包含地址,并以这种方式创建:

DBUS_CMD="dbus-daemon --fork --print-address 5 --print-pid 6 --session"
OMXPLAYER_DBUS_ADDR="/tmp/omxplayerdbus.${USER:-root}"
OMXPLAYER_DBUS_PID="/tmp/omxplayerdbus.${USER:-root}.pid"
exec 5> "$OMXPLAYER_DBUS_ADDR"
exec 6> "$OMXPLAYER_DBUS_PID"
$DBUS_CMD

DBUS_SESSION_BUS_ADDRESS=`cat $OMXPLAYER_DBUS_ADDR`
DBUS_SESSION_BUS_PID=`cat $OMXPLAYER_DBUS_PID`

export DBUS_SESSION_BUS_ADDRESS
export DBUS_SESSION_BUS_PID

OMXPLAYER_DIR="/usr/bin"
OMXPLAYER_BIN="$OMXPLAYER_DIR/omxplayer.bin"
$OMXPLAYER_BIN "$@"

现在我想启动另一个 omxplayer 实例,我想从 DBus 控制它。

每次提供不同的地址时我都需要分叉 dbus-daemon 并且在我的应用程序中我必须连接到相关的总线?在这种情况下,我必须在关联的 omxplayer 结束时终止分叉进程?

4

0 回答 0