13

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"
    "os"

    "github.com/guelfey/go.dbus"
    "github.com/guelfey/go.dbus/introspect"
)

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)
}
Eugene Mikhalev
  • 598
  • 3
  • 13
Majormjr
  • 183
  • 1
  • 2
  • 7
  • you have to use the content of the files - the address looks something like unix:abstract=/tmp/dbus-mQJTjffxVL,guid=cb5b9d6eb7d17e381a9ce1c2590d99aa but I'm still not able to call any dbus function for omxplayer – lumos0815 May 06 '17 at 09:47

1 Answers1

0

OMXplayer does not use the system or session bus, but instead uses its own bus, the path to this bus is the content of the file pointed to by the OMXPLAYER_DBUS_ADDR environment variable.

You can see that the dbuscontrol.sh script sets that up on lines 5-8 (specifically line 7).

In your case, you'll need to open that file, read its contents, and use that in a call to dbus.Conn.Dial().

Something similar to this may work:

import (
    "log"
    "io/ioutil"
    "github.com/guelfey/go.dbus"
)

func getOMXPlayerDBUSAddr() string {
    content, err := ioutil.ReadFile("/tmp/omxplayerdbus.pi")
    if err != nil {
        log.Fatal(err)
    }

    return string(content)
}

func main() {
    conn, err := dbus.Dial(getOMXPlayerDBUSAddr())
    if err != nil {
        panic(err)
    }

    // The rest of the code goes here
    node, err := introspect...
}
T0xicCode
  • 4,583
  • 2
  • 37
  • 50