snaums
/
PiPlayer
Архівний
1
0
Форк 0
Simple GUI around OMXPlayer for Raspberry Pi
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
Цей репозиторій архівовано. Ви можете переглядати файли та клонувати його, але не можете виконувати push чи відкривати задачі та запити злиття.
 
 

148 рядки
3.9 KiB

from fltk import *
import sys
import subprocess
import re
import time
import genericThread
import config
import fileio
import ui
omx = genericThread.genericThread ( 1, "OMX", 1);
state = genericThread.genericThread ( 2, "State", 2);
stateRun = True;
live=False;
def startOMX ( argv ):
global stateRun
argv=argv[0];
stream = argv.pop();
i = 0;
output = "local"
while ( i < len(argv) ):
if ( argv[i] =="-o"):
if ( argv[i+1] == "local" or argv[i+1] == "hdmi" ):
output=argv[i+1];
else:
output="local"
i = i + 1
(x,y,x2,y2) = ui.sizeCalc();
argv = [ "omxplayer", "--win", str(x)+","+str(y)+","+str(x2)+","+str(y2), "-o", output, "--aspect-mode", "letterbox", stream ];
subprocess.run ( argv );
stateRun = False;
def startOMXLive ( argv ):
global stateRun
quality=argv[1];
argv=argv[0];
stream = argv.pop();
i = 0;
output = "local"
while ( i < len(argv) ):
if ( argv[i] =="-o"):
if ( argv[i+1] == "local" or argv[i+1] == "hdmi" ):
output=argv[i+1];
else:
output="local"
i = i + 1
(x,y,x2,y2) = ui.sizeCalc();
argv = [ "livestreamer", stream, quality, "-np",
"omxplayer --win "+str(x)+","+str(y)+","+str(x2)+","+str(y2)+" -o "+output+" --aspect-mode letterbox --live" ];
print (argv);
subprocess.run ( argv );
stateRun = False;
def thread_state ( args ) :
global stateRun
global live
beginTime = int(time.time());
if ( live == False ):
while ( stateRun == True ):
ui.getState( None );
time.sleep (1);
else :
while ( stateRun == True ):
ui.statusLabel.value ( "Uptime: " + ui.timeOut ( (int(time.time()) - beginTime)*1000000 ))
time.sleep(1);
def killAll ( cfg ):
global stateRun
stateRun = False;
ui.callDBus ( ["stop"] );
cfg["WindowX"] = ui.window.x();
cfg["WindowY"] = ui.window.y();
cfg["WindowWidth"] = ui.window.w();
cfg["WindowHeight"] = ui.window.h();
fileio.saveConfig ( config.configfile, cfg );
state.join();
omx.join();
sys.exit(0);
def FLTK_run () :
global stateRun
x = ui.window.x();
y = ui.window.y();
w = ui.window.w();
h = ui.window.h();
while (stateRun == True and ui.window.shown()):
Fl.check();
if ( x != ui.window.x() or y != ui.window.y() or
w != ui.window.w() or h != ui.window.h() ):
ui.resizeWindow ();
if (Fl.event_button1() and
Fl.event_inside ( ui.statusProgress.x(),
ui.statusProgress.y(),
ui.statusProgress.x() + ui.statusProgress.w(),
ui.statusProgress.y() + ui.statusProgress.h() ) ):
ui.seekCb ();
time.sleep(0.1); # I don't want to burn that much cpu-time
def main () :
global live
if ( len ( sys.argv ) <= 1 ):
print ("Usage: " + sys.argv[0] + " [parameters] FILENAME\n\
Options:\n\
* --live - indicate that a livestream is played (i.e. Twitch), will be played using livestreamer");
sys.exit(0);
i = 0
quality = "best"
live = False;
omx.setFn ( startOMX, [sys.argv[1:]] );
while ( i < len (sys.argv) ):
if (sys.argv[i] == "--live"):
live = True
if (sys.argv[i] == "--quality" or sys.argv[i] =="-q"):
quality=sys.argv[1+i];
i = i + 1;
print (quality)
if ( live == True ):
omx.setFn ( startOMXLive, [sys.argv[1:], quality] );
state.setFn ( thread_state, [] );
cfg = fileio.getConfig ( config.configfile );
ui.init( cfg );
# start omx-player
omx.start();
state.start();
FLTK_run ();
killAll( cfg )
if __name__ == "__main__" :
main()