Avatar ·

Raspberry Pi + omxplayer-wrapper - launching video files in the required order by button presses

📁 function, Advanced Python Topics, example, bots, AI, work

I'm trying to launch video files from Python on Raspberry Pi. For this I'm using omxplayer-wrapper.

I'm trying to implement the following algorithm:

  1. At the start of the program, file a.mp4 is played
  2. When button 1 is pressed, a.mp4 stops and b.mp4 starts. When it finishes, a.mp4 starts again
  3. When button 2 is pressed, a.mp4 stops and c.mp4 starts. When it finishes, a.mp4 starts again

The algorithm works, but the following drawbacks are observed:

  1. After file b.mp4 finishes playing, the desktop is visible before a.mp4 starts (about 1 second)
  2. After file c.mp4 finishes playing, the desktop is visible for even longer before a.mp4 starts (about 10-12 seconds)
Avatar ·

I see 2 options for solving the problem. Either use pause/load

from omxplayer import OMXPlayerfrom gpiozero import Buttonplayer = OMXPlayer('path/to/a.mp4', args=['-b', '--loop'])button1 = Button(1)button2 = Button(2)player.play()while True:    if button1.is_pressed:        player.pause()        player.load('path/to/b.mp4')        player.play()    elif button2.is_pressed:        player.pause()        player.load('path/t

Log in to leave an answer

Blogs