jleight / omxplayer

Library for controlling OMXPlayer via D-Bus in Go.
MIT License
21 stars 12 forks source link

dbuscontrol.sh script works while example in README does not. #1

Open hagna opened 9 years ago

hagna commented 9 years ago

omxplayer is Version : 843744e [master](Build date: Sat, 27 Jun 2015 00:49:24 +0000) golang is 1.4.2 cross compiler for arm (5g) you can find dbuscontrol.sh (which does work) here https://github.com/popcornmix/omxplayer/blob/master/dbuscontrol.sh

The code I run is the example provided with logging:

package main

import (
    "github.com/jleight/omxplayer"
    "log"
    "time"
)

func main() {
    log.SetFlags(log.Lshortfile)
    omxplayer.SetUser("root", "/root")
    player, err := omxplayer.New("/root/testvideo.mp4")
    if err != nil {
        log.Println(err)
    }

    player.WaitForReady()
    err = player.PlayPause()
    if err != nil {
        log.Println(err)
    }

    time.Sleep(5 * time.Second)
    err = player.ShowSubtitles()
    if err != nil {
        log.Println(err)
    }

    time.Sleep(5 * time.Second)
    err = player.Quit()
    if err != nil {
        log.Println(err)
    }
}

And this is what it does:

root@raspberrypi:~# ./omx 
main.go:20: The name org.mpris.MediaPlayer2.omxplayer was not provided by any .service files
main.go:26: Message did not receive a reply (timeout by message bus)
main.go:32: The name org.mpris.MediaPlayer2.omxplayer was not provided by any .service files

Although if I can use dbuscontrol.sh while ./omx is running to see that the video is paused:

root@raspberrypi:~# ./dbuscontrol.sh status
Duration: 9088000
Position: -200000
Paused: true
jleight commented 9 years ago

I am able to reproduce this issue with the pre-installed version of omxplayer on a freshly imaged Pi using the 2015-05-05 stock Raspbian image.

It looks like properties under the org.freedesktop.DBus.Properties interface—CanQuit, Duration, Position, etc.—are working, but anything under the org.mpris.MediaPlayer2.Player interface—PlayPause, ShowSubtitles, etc.—are giving the "missing .service file" error.

I will continue looking into this issue as my free time permits.

jleight commented 9 years ago

Upon further investigation, this looks like a timing issue. If I add a five second sleep before the initial call to player.PlayPause(), everything seems to work fine:

player.WaitForReady()
time.Sleep(5 * time.Second)
err = player.PlayPause()

Clearly the player.WaitForReady() is not fulfilling it's intended purpose. I'll continue trying to figure out a better implementation for it.

hagna commented 9 years ago

Even if I pause for 15 seconds ShowSubtitles will not work.