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

How do I know video is ended? #120

Closed imababo closed 5 years ago

imababo commented 6 years ago

I'm beginner on python. I develop video player with omxplayer. I want to do as follows:

  1. I play video file. omxplayer -o hdmi --no-osd video.mp4 echo -n p > fifo g_player = OMXPlayer(movie, args)
  2. Play video is ended. I didn't stop video. video playing is ended after video's playing duration.
  3. I want to play another video file. But, I don't know whether the video is ended. the function 'onStop()' is not called when video is ended. (I know the function 'onStop()' is called when I stopped video.)

I need anybody's help.

The below is snippet of my python codes:

def create_player(movie, args): global g_player g_player = OMXPlayer(movie, args)

g_player.playEvent += onPlay
g_player.pauseEvent += onPause
g_player.stopEvent += onStop

def onStop(player): video = another.mp4 create_player(movie) g_player.play()

args = [] args.append('--no-osd') movie = video.mp4 create_player(movie, args) g_player.play()

Leocoe commented 6 years ago

Ran into the same problem. See also this discussion Seems like there is no handy way to do it. So you will have to run something like the following in a loop or separate thread.

try:
    stat = player.playback_status()
    # check stat if you like, maybe reacting to Stopped if user can stop it..
except OMXPlayerDeadError err:
    # presumably the video/audio playback ended. do what you need to do..
    pass
willprice commented 5 years ago

See https://github.com/willprice/python-omxplayer-wrapper/issues/73