snaums
/
PiPlayer
Archived
1
0
Fork 0
Browse Source

added loop-feature

master
Stefan Naumann 5 years ago
parent
commit
b1ffd62138
  1. 2
      cfg/config.json
  2. 25
      src/fileio.py
  3. 43
      src/piplayer.py
  4. 36
      src/ui.py

2
cfg/config.json

@ -1 +1 @@
{"WindowX": 4, "WindowY": 47, "WindowWidth": 647, "WindowHeight": 553}
{"WindowX": 1, "WindowY": 47, "WindowWidth": 639, "WindowHeight": 452, "Loop": false}

25
src/fileio.py

@ -9,18 +9,25 @@ import json
def getConfig ( pathname ):
data = {};
print (pathname);
with open( pathname, "r+" ) as f:
val = f.read();
try:
data = json.loads(val)
except ValueError:
print ("Oeeehm");
data = {}
try :
with open( pathname, "r+" ) as f:
val = f.read();
try:
data = json.loads(val)
except ValueError:
print ("Oeeehm");
data = {}
except:
pass
return (data);
## save a config-dictionary to a file
# @param pathname the path to the config-file
# @param data dictionary containing config-information
def saveConfig ( pathname, data ):
with open( pathname, 'w') as f:
json.dump(data, f)
try:
with open( pathname, 'w') as f:
json.dump(data, f)
except:
print ("Error on Config-save!")
pass

43
src/piplayer.py

@ -6,12 +6,15 @@ import sys
import subprocess
import re
import time
import fcntl
import genericThread
import config
import fileio
import ui
## omx-thread, which calls omxplayer and waits for it to finish
omx = genericThread.genericThread ( 1, "OMX", 1);
## state-thread which calls omxplayer for the state of the playback (position, duration, playback-state)
@ -21,11 +24,17 @@ stateRun = True;
## is the application run in live-mode (i.e. using livestreamer, not omxplayer directly)
live=False;
## lock file for ensuring that PiPlayer can only be called once (for playlists)
pid_file = '/tmp/piplayer.pid'
## file descriptor for the lock-file
fd=0
## start OMXplayer for playback of local files or remote files (not livestreams)
# @param argv arguments to the python-skript piplayer.py with information about file, etc
# @note called from a thread
def startOMX ( argv ):
global stateRun
global loop
argv=argv[0];
stream = argv.pop();
@ -40,9 +49,12 @@ def startOMX ( argv ):
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 );
first = True;
while ( ui.loop == True or first == True ):
first=False
(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;
## start OMXplayer for playback of livestreams, invokes livestreamer
@ -50,6 +62,7 @@ def startOMX ( argv ):
# @note called from a thread
def startOMXLive ( argv ):
global stateRun
global loop
quality=argv[1];
argv=argv[0];
@ -65,10 +78,13 @@ def startOMXLive ( argv ):
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" ];
subprocess.run ( argv );
first = True;
while ( ui.loop == True or first == True ):
first=False
(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" ];
subprocess.run ( argv );
stateRun = False;
## calls omxplayer for its current state repeatedly
@ -96,11 +112,13 @@ def killAll ( cfg ):
cfg["WindowY"] = ui.window.y();
cfg["WindowWidth"] = ui.window.w();
cfg["WindowHeight"] = ui.window.h();
cfg["Loop"]=ui.loop;
fileio.saveConfig ( config.configfile, cfg );
state.join();
omx.join();
fd.close ();
sys.exit(0);
## main-loop for FLTK, which updates the window and the omxplayer
@ -132,6 +150,15 @@ def FLTK_run () :
## main-function for PiPlayer
def main () :
global live
global fd
global pip_file
fd = open(pid_file, 'w')
try:
fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
# another instance is running
sys.exit(0)
if ( len ( sys.argv ) <= 1 ):
print ("Usage: " + sys.argv[0] + " [parameters] FILENAME\n\
@ -153,14 +180,12 @@ Options:\n\
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

36
src/ui.py

@ -16,6 +16,9 @@ durationState = 0;
## indicates the current playback-position in mikroseconds
positionState = 0;
## loop the current video and or playlist?
loop = False;
## unused at the moment
dbusaddr = "org.mpris.MediaPlayer2.omxplayer"
@ -48,6 +51,17 @@ def playCb(ptr):
else :
playBtn.label("@>");
## callback for the loop-button clck - toggle the loop-state
# @param ptr unused, but needed for FLTK
def loopBtnCb ( ptr ):
global loopBtn
global loop
if ( loop == True ) :
loop = False;
else:
loop = True;
loopBtn.value ( loop );
## decodes the output of dbuscontrol.sh (already split by "\n")
# @param split string(!) of the output of dbuscontrol.sh
def DecodeState ( param ):
@ -110,6 +124,7 @@ def resizeWindow ( ):
global killBtn
global statusLabel
global statusProgress
global loopBtn
global volUp
global volDown
@ -120,15 +135,17 @@ def resizeWindow ( ):
playBtn.position ( 20, h-60 );
stateBtn.position ( 60, h-60);
killBtn.position ( 100, h-60 );
loopBtn.position ( 140, h-60 );
volUp.position ( w - 40, h-50 );
volDown.position ( w - 60, h-50 );
statusProgress.position ( 160, h-50 );
statusProgress.size ( w - 410, 20 );
statusProgress.position ( 200, h-50 );
statusProgress.size ( w - 450, 20 );
playBtn.redraw();
stateBtn.redraw();
killBtn.redraw();
loopBtn.redraw();
#statusLabel.redraw();
statusProgress.redraw();
window.redraw();
@ -215,6 +232,8 @@ playBtn=""
stateBtn=""
## Button object for the quit-button
killBtn=""
## Button object for the loop-buttn
loopBtn=""
## Output object for the statusLabel-Output
statusLabel=""
## progressBar-object for the progress bar on the bottom of the player
@ -236,6 +255,11 @@ def init ( cfg ):
global volUp
global volDown
global stateBtn
global loopBtn
global loop;
loop = cfg.get("Loop", False );
window = Fl_Window( cfg.get("WindowX", 100) , cfg.get("WindowY", 100), cfg.get("WindowWidth", 640), cfg.get("WindowHeight", 480))
window.label("PiPlayer")
window.size_range ( 320, 240, 0, 0);
@ -257,12 +281,18 @@ def init ( cfg ):
## TODO
killBtn.callback ( piplayer.killAll );
killBtn.box ( FL_THIN_UP_BOX );
loopBtn = Fl_Button ( 140, 420, 40, 40 );
loopBtn.label ('L');
loopBtn.callback ( loopBtnCb );
loopBtn.box ( FL_THIN_UP_BOX );
loopBtn.value ( loop );
statusLabel = Fl_Output ( 410, 430, 150, 20 );
statusLabel.label ("");
statusLabel.box ( FL_FLAT_BOX );
statusProgress = Fl_Progress ( 160, 430, 230, 20 );
statusProgress = Fl_Progress ( 200, 430, 190, 20 );
statusProgress.box( FL_FLAT_BOX );
statusProgress.minimum(0);
statusProgress.maximum(1);