User avatar
rpiMike
Posts: 1391
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Python omxplayer wrapper : exitEvent

Mon Nov 26, 2018 5:56 pm

Anyone know how the use the exitEvent correctly in the omxplayer wrapper?

I'm using 0.3.2 :

pi@raspberrypi:~ $ pip3 show omxplayer-wrapper
Name: omxplayer-wrapper
Version: 0.3.2

Using the following code:

Code: Select all

from omxplayer.player import OMXPlayer
import time,signal,sys

def signalHandler(sig,frame):
    print('Ctrl+C pressed')
    player.quit()
    sys.exit(0)
    
def playerPause():
    print('pause')

def playerExit():
    print('exit')

signal.signal(signal.SIGINT,signalHandler)

filename = './Simple Minds/Glittering Prize 81-92 [Canada]/01 Waterfront.mp3'

player = OMXPlayer(filename)
player.pauseEvent += lambda _: playerPause()    
player.exitEvent += lambda _: playerExit()

time.sleep(3) # wait for omxplayer

player.set_position(player.duration()-5) # skip close to end

while True:
    time.sleep(1)
I get :

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/.local/lib/python3.5/site-packages/omxplayer/player.py", line 173, in monitor
on_exit(self, process.returncode)
File "/home/pi/.local/lib/python3.5/site-packages/omxplayer/player.py", line 169, in on_exit
self.exitEvent(self, exit_status)
File "/home/pi/.local/lib/python3.5/site-packages/evento/event.py", line 48, in fire
subscriber(*args, **kargs)
TypeError: <lambda>() takes 1 positional argument but 2 were given

I assume its something to do with the exit_status parameter in the documentation below:

https://python-omxplayer-wrapper.readth ... omxplayer/
exitEvent = None
Event called on exit callback(player, exit_status)

DirkS
Posts: 10371
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Python omxplayer wrapper : exitEvent

Mon Nov 26, 2018 6:47 pm

https://github.com/willprice/python-omx ... r/pull/116 (pull request that introduced the feature) uses this as examples:

Code: Select all

player.exitEvent += lambda _, exit_code: print("OK") if exit_code == 0 else print("NOT OK")
and
player.exitEvent += lambda _, _: print("OMXPLAYER TERMINATED")
Notice it uses 2 arguments

Not 100% sure, but I think this may be relevant:
https://stackoverflow.com/questions/519 ... ambda-expr

User avatar
rpiMike
Posts: 1391
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Python omxplayer wrapper : exitEvent

Mon Nov 26, 2018 7:00 pm

Thank you, that helped.

Code: Select all

def playerExit(code):
    print('exit',code)

player.exitEvent += lambda _, exit_code: playerExit(exit_code)

Return to “Python”