willprice / python-omxplayer-wrapper

:tv: Control OMXPlayer, the Raspberry Pi media player, from Python
http://python-omxplayer-wrapper.readthedocs.io
GNU Lesser General Public License v3.0
253 stars 71 forks source link

dbus.exceptions.DBusException in player.set_position() #76

Closed wmodes closed 6 years ago

wmodes commented 7 years ago

Issue Report

Description

Keep running into episodic dbus.exceptions.DBusException in position() and set_position() methods

Problem reproduction

Hmm, wondering whether you will be able to reproduce it, since it happens consistently, but not reliably for me.

def debug(*args):
    if (DEBUG):
        text = " ".join(list(map(str, args)))
        print text

def play_film(player, filename="demo.mp4", duration=0, position=0):
    debug("\nfilename:", filename)
    debug("  position:", position)
    debug("  duration:", duration)
    trim_from_end = 0.5
    #trim_from_end = 0
    player.load(filename)
    player.set_position(0.0)
    debug("  pre-play pos:", player.position())
    player.play()
    # check and set position
    full_length = player.duration()
    # if the position is imposible, set it to 0
    if position <= 0 or position > full_length:
        position = 0.0
    player.set_position(position)
    # check and set duration
    length_to_end = player.duration()
    # if duration is imposible, set it to the length_to_end
    if duration == 0 or duration > length_to_end:
        wait = length_to_end - trim_from_end
    else:
        wait = duration
    if wait < 0:
        wait = 0
    debug("  full length: ", full_length)
    debug("  length to end: ", length_to_end)
    debug("  wait: ", wait)
    sleep(wait)
    debug("  post sleep pos:", player.position())
    #player.pause()
    #player.stop()
    debug("  post pause pos:", player.position())
    return True

def main():
        player = OMXPlayer("1960s-cuba-family.mp4")
        play_film(player, "1960s-cuba-family.mp4", duration=1)

Results in:

$ python omx-test2.py 

filename: 1960s-cuba-family.mp4
  position: 0
  duration: 10
Traceback (most recent call last):
  File "omx-test2.py", line 83, in <module>
    main()
  File "omx-test2.py", line 75, in main
    play_film(player, choice(rotate_films), duration=10)
  File "omx-test2.py", line 39, in play_film
    player.set_position(0.0)
  File "<decorator-gen-24>", line 2, in set_position
  File "build/bdist.linux-armv7l/egg/omxplayer/player.py", line 141, in wrapped
  File "build/bdist.linux-armv7l/egg/omxplayer/player.py", line 367, in set_position
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Message did not receive a reply (timeout by message bus)

Another variation on this is this one:

filename: 1960s-family-movie.mp4
  position: 0
  duration: 10
Traceback (most recent call last):
  File "omx-test2.py", line 83, in <module>
    main()
  File "omx-test2.py", line 75, in main
    play_film(player, choice(rotate_films), duration=10)
  File "omx-test2.py", line 39, in play_film
    player.set_position(0.0)
  File "<decorator-gen-24>", line 2, in set_position
  File "build/bdist.linux-armv7l/egg/omxplayer/player.py", line 141, in wrapped
  File "build/bdist.linux-armv7l/egg/omxplayer/player.py", line 367, in set_position
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name :1.565 was not provided by any .service files

Environment details

Software Version
python-omxplayer-wrapper 0.2.0
python-dbus (dpkg -s python-dbus) 1.2.0-2
python (python --version) 2.7.9
omxplayer (omxplayer --version) dfea8c9
willprice commented 6 years ago

Can't reproduce with your exact code, but pretty sure its because you've commented out that player.stop() line, with it in you're executing a dbus method after stopping the player, which kills the process, so any further dbus method calls will fail, hence player.position() will fail.