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

OMXplayer process dies at completion of video? #141

Closed Landfishy closed 5 years ago

Landfishy commented 5 years ago

Hi there guys, I don't know if this is a bug or not. If I let a video run to completion, I cannot call the instantiated OMXplayer to run a new video. I get an error:

raise OMXPlayerDeadError('Process is no longer alive, cant\'t run command') omxplayer.player.OMXPlayerDeadError: Process is no longer alive, can't run command.

I was trying to monitor the status of the video player so that I could know when other content should be loaded, and was filtering out exceptions when I discovered the process was actually dying as it returned exceptions. When when I tried to send it a command after that, obviously things blew up. Heres some pseudo code for the use case...is there something I am doing wrong or is this actually an issue?

from omxplayer import OMXPlayer

class VideoPlayer(): 
    def __init__ (self):
        self.omx = None

    def Playloop(self, fullpath, startPosition):
        self.omx = OMXPlayer(fullpath, args=['-o', 'hdmi', '--no-osd', '--alpha', '80'])

def runProgram():
    myBGPlayer = VideoPlayer()
    myBGplayer.PlayLoop('/etc/media/Ball.mp4')

    while(1):
        try:
            #  Check for single player status once the player has been instantiated
            if myBGPlayer.omx:
                status = myPlayer.omx.playback_status()
            else:
                status = 'stopped'
        except:
            print("An exception occurred 001")
willprice commented 5 years ago

You'll need to load a new video once the first one completes. I think the changes from https://github.com/willprice/python-omxplayer-wrapper/pull/116 will allow you to implement what you're after.

Basically you'll want to register a callback on exitEvent to do something when the video finishes.