snaums
/
PiPlayer
Archived
1
0
Fork 0
Simple GUI around OMXPlayer for Raspberry Pi
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
PiPlayer/src/piplayer.py

269 lines
6.7 KiB

from fltk import *
import sys
import os
import subprocess
import re
import time
import threading
playState = True;
durationState = 0;
positionState = 0;
class genericThread ( threading.Thread ):
def __init__ (self, threadID, name, counter):
threading.Thread.__init__(self);
self.threadID = threadID
self.name = name
self.counter = counter
self.fn = None;
self.args=[];
def run( self ):
self.fn(self.args);
def setFn ( self, fn, args ):
self.fn = fn
self.args = args
def startOMX ( argv ):
global stateRun
argv=argv[0];
argv.insert ( 0, "omxplayer" )
argv.append ( "--win");
(x,y,x2,y2) = sizeCalc();
argv.append( str(x)+","+str(y)+","+str(x2)+","+str(y2) )
argv.append ( "-o");
argv.append("local");
argv.append("--aspect-mode");
argv.append("letterbox");
subprocess.run ( argv );
print ( "OMX finished");
stateRun = False;
def callDBus ( param ):
try:
param.insert ( 0, "/opt/dbuscontrol.sh" );
param.insert ( 0, "bash" );
out = subprocess.check_output ( param )
return out;
except subprocess.CalledProcessError:
#print ("An Error occured while calling dbuscontrol.hs");
return b"";
def playCb(ptr):
callDBus ( ["pause"] );
getState( None );
global playState
if ( playState == True ):
playBtn.label ("@||");
else :
playBtn.label("@|>");
def resizeCb ():
(x,y,x2,y2) = sizeCalc()
status = callDBus ( ["status"] );
times = 0;
while (status=="" and times < 5) :
status = callDBus ( ["status"] );
time.sleep ( 0.5 );
times = times + 1;
if ( times < 5 ):
callDBus (["setvideopos", str(x), str(y), str(x2), str(y2)]);
def sizeCalc ( ):
global window
x = window.x();
y = window.y();
w = window.w();
h = window.h();
#x=x+2;
#y=y+2;
x2 = x + w;
y2 = y + h - 75;
return (x,y,x2,y2);
def DecodeState ( param ):
global playState;
global durationState;
global positionState;
i=0
while (i < len(param)) :
m = re.search ( "Duration: ([0-9]+)", param[i] );
if ( m is None ):
m = re.search ( "Position: ([0-9]+)", param[i] );
if ( m is None ):
m = re.search ( "Pause: (\(true|false)\)", param[i] );
if ( m is None ) :
pass;
else :
playState = ( m.group(1) == "true");
else:
positionState = int ( m.group(1) );
else:
durationState = int ( m.group(1) );
i=i+1
def timeOut ( time ) :
time = int(time / 1000000); # mikrosec -> sec
hours = int(time / 3600);
minutes = int((time / 60)) - hours*60;
sec = time - minutes*60 - hours*360;
return ( str(hours).zfill(2) + ":" + str(minutes).zfill(2) + ":" +str(sec).zfill(2) );
def setPosition ( pos ):
callDBus ( ["setposition", str(pos)] );
getState ( None );
def getState ( ptr ) :
status = callDBus ( ["status"] );
status = status.decode("utf-8").split("\n")
DecodeState ( status );
statusLabel.value ( timeOut ( positionState ) + " / " + timeOut ( durationState ) );
if ( durationState == 0):
statusProgress.value(0);
else :
statusProgress.value( positionState / durationState );
stateRun = True;
def thread_state ( args ) :
global stateRun;
while ( stateRun == True ):
getState( None );
time.sleep (1);
omx = genericThread ( 1, "OMX", 1);
state = genericThread ( 2, "State", 2);
def killAll ( ptr ):
global stateRun;
stateRun = False;
callDBus ( ["stop"] );
state.join();
omx.join();
sys.exit(0);
def FLTK_run () :
global stateRun
global window
global statusProgress
x = window.x();
y = window.y();
w = window.w();
h = window.h();
while (stateRun == True and window.shown()):
Fl.check();
if ( x != window.x() or y != window.y() or
w != window.w() or h != window.h() ):
resizeWindow ();
if (Fl.event_button1() and Fl.event_inside ( statusProgress.x(), statusProgress.y(), statusProgress.x() + statusProgress.w(), statusProgress.y() + statusProgress.h() ) ):
seekCb ();
time.sleep(0.1); # I don't want to burn that much cpu-time
def resizeWindow ( ):
global window;
global playBtn
global stateBtn
global killBtn
global statusLabel
global statusProgress
global volUp
global volDown
h = window.h()
w = window.w()
statusLabel.resize ( w-230, h-50, statusLabel.w(), statusLabel.h() );
playBtn.position ( 20, h-60 );
stateBtn.position ( 60, h-60);
killBtn.position ( 100, h-60 );
volUp.position ( w - 40, h-50 );
volDown.position ( w - 60, h-50 );
statusProgress.position ( 160, h-50 );
statusProgress.size ( w - 410, 20 );
playBtn.redraw();
stateBtn.redraw();
killBtn.redraw();
#statusLabel.redraw();
statusProgress.redraw();
window.redraw();
resizeCb ();
def seekCb ():
global statusProgress;
x = Fl.event_x();
x = x - statusProgress.x();
dim = x / statusProgress.w();
positionState = durationState * dim;
setPosition ( positionState );
def volUpCb ( ptr ):
callDBus ( ["volumeup"] );
def volDownCb ( ptr ):
callDBus ( ["volumedown"] );
if ( len ( sys.argv ) <= 1 ):
print ("Usage: " + sys.argv[0] + "[omxplayer-arguments] FILENAME");
killAll();
omx.setFn ( startOMX, [sys.argv[1:]] );
state.setFn ( thread_state, [] );
window = Fl_Window(100,100,640,480)
window.label(sys.argv[0])
window.size_range ( 320, 240, 0, 0);
# start omx-player
omx.start();
playBtn = Fl_Button(20, 420, 40, 40)
playBtn.label("@|>")
playBtn.callback(playCb)
playBtn.box ( FL_THIN_UP_BOX );
stateBtn = Fl_Button ( 60, 420, 40, 40 );
stateBtn.label("?")
stateBtn.callback(getState)
stateBtn.box ( FL_THIN_UP_BOX );
killBtn = Fl_Button ( 100, 420, 40, 40 );
killBtn.label ("x");
killBtn.callback ( killAll );
killBtn.box ( FL_THIN_UP_BOX );
statusLabel = Fl_Output ( 410, 430, 150, 20 );
statusLabel.label ("");
statusLabel.box ( FL_FLAT_BOX );
statusProgress = Fl_Progress ( 160, 430, 230, 20 );
statusProgress.box( FL_FLAT_BOX );
statusProgress.minimum(0);
statusProgress.maximum(1);
statusProgress.color ( 0xffffffff );
statusProgress.selection_color( 0x272828ff );
volUp = Fl_Button ( 600, 430, 20,20 );
volUp.label ( "+" );
volUp.box ( FL_THIN_UP_BOX );
volUp.callback ( volUpCb );
volDown = Fl_Button ( 580, 430, 20,20 );
volDown.label ( "-" );
volDown.box ( FL_THIN_UP_BOX );
volDown.callback ( volDownCb );
window.end()
window.show(len(sys.argv), sys.argv)
state.start();
FLTK_run ();
killAll( None )