duanjing7298 2015-01-19 17:11
浏览 112

在Raspberry Pi上将go.dbus与omxplayer一起使用

I am trying to using the D-Bus interface on omxplayer in order to control the running video. I'm attempting this using the go.dbus library found here: https://github.com/guelfey/go.dbus

The omxplayer documentation provides a dbuscontrol.sh script that I can use successfully. It sets some environments variable and then can use dbus-send in order to query omxplayer.

I'm trying to reproduce this in Go but I keep getting the error "The name org.mpris.MediaPlayer2 was not provided by any .service files"

Here is my code:

package main

import (
    "encoding/json"
    "fmt"
    "github.com/guelfey/go.dbus"
    "github.com/guelfey/go.dbus/introspect"
    "os"
)

func main() {
    os.Setenv("OMXPLAYER_DBUS_ADDR", "/tmp/omxplayerdbus.pi")
    os.Setenv("OMXPLAYER_DBUS_PID", "/tmp/omxplayerdbus.pi.pid")
    conn, err := dbus.SessionBus()
    if err != nil {
        panic(err)
    }
    node, err := introspect.Call(conn.Object("org.mpris.MediaPlayer2.omxplayer", "/org/mpris/MediaPlayer2"))
    if err != nil {
        fmt.Println(err)
    }
    data, _ := json.MarshalIndent(node, "", "    ")

    var s []string
    err = conn.BusObject().Call("org.freedesktop.DBus.ListNames", 0).Store(&s)
    if err != nil {
        fmt.Fprintln(os.Stderr, "Failed to get list of owned names:", err)
        os.Exit(1)
    }

    fmt.Println("Currently owned names on the session bus:")
    for _, v := range s {
        fmt.Println(v)
    }

    os.Stdout.Write(data)
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题