Trying to run video files from Raspberry Pi from python.
For this I use omxplayer-wrapper .
I am trying to implement the following algorithm:
- At the beginning of the program, the a.mp4 file is played.
- When you press button 1, a.mp4 stops and turns on b.mp4. When it finishes, a.mp4 turns on again.
- When you press button 2, a.mp4 stops and c.mp4 turns on. When it finishes, a.mp4 turns on again.
The algorithm works, but the following disadvantages are observed:
- After b.mp4 finishes playing, before launching a.mp4, the desktop is visible (approximately 1 second)
- After the c.mp4 file finishes playing, before launching a.mp4, the desktop can be seen for more time (approximately 10-12 seconds)
How to carry out this task correctly?
I give a sketch of the code:
from omxplayer import OMXPlayer from time import sleep playerA = OMXPlayer('path/to/a.mp4', args=['-b', '--loop']) playerB = OMXPlayer('path/to/b.mp4', args=['-b']) playerC = OMXPlayer('path/to/c.mp4', args=['-b']) playerA.play() while True: if Button1PressedFlag==True: #set in interrupt Button1PressedFlag=False playerA.pause() playerB.play() while playerB.is_playing(): sleep(0.2) playerB.quit() playerA.play() if Button2PressedFlag==True: #set in interrupt Button2PressedFlag=False playerA.pause() playerC.play() while playerC.is_playing(): sleep(0.2) playerC.quit() playerA.play() UPD:
Last night I checked - in general, tin.is_playing either works or does not work.
Where is_playing() does not work, the playback_status(), function works playback_status(), although it is used in is_playing() ..quit() then kills the process, then no.stop() then stops the player, then kills the process
Porridge is terrible ..
Solved the problem with a dirty trick:
1. Run video
2. I take its duration and insert it into sleep()
3. after slip kill video
If you need to switch the video, the switch occurs in the interrupt from the button.
It seems to work ... But not beautiful somehow ... :(
stopinstead ofquit, so as not to restart the player once again and not waste resources on a weak computer? It would be nice to catch where exactly the delay occurs in the code. Still, to unload the device, you can run the application without DE, especially, as I understand it, you need the "kiosk" mode, the desktop does not need anything. - approximatenumberraspi-configyou can configure the init-level, in which the OS will boot without loadingXes andDE. And then you can manually start the Xs and your application. Here , for example, you can read how to run a GUI application without a graphical environment. - approximatenumber