Browse Source

added buttons for switching audio tracks and subtitles (needs more work), painted player background black (useful for OMX)

master
Stefan Naumann 2 years ago
parent
commit
219fb6ec6f
  1. 106
      data/gtplay.glade
  2. 19
      dbuscontrol.sh
  3. 7
      src/gtplay.py
  4. 33
      src/mainWindow.py
  5. 40
      src/omxplayer.py
  6. 2
      src/playlist.py

106
data/gtplay.glade

@ -7,6 +7,11 @@
<property name="can_focus">False</property>
<property name="icon_name">view-restore</property>
</object>
<object class="GtkImage" id="hideImg">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">emblem-unreadable</property>
</object>
<object class="GtkImage" id="jumpBackImg">
<property name="visible">True</property>
<property name="can_focus">False</property>
@ -17,21 +22,26 @@
<property name="can_focus">False</property>
<property name="icon_name">media-seek-forward</property>
</object>
<object class="GtkImage" id="hideImg">
<object class="GtkImage" id="loopImg">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">emblem-unreadable</property>
<property name="icon_name">media-playlist-repeat</property>
</object>
<object class="GtkImage" id="loopImg">
<object class="GtkImage" id="nextAudioImg">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">media-playlist-repeat</property>
<property name="icon_name">audio-volume-medium</property>
</object>
<object class="GtkImage" id="nextImg">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">media-skip-forward</property>
</object>
<object class="GtkImage" id="nextSubtitleImg">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">format-indent-more</property>
</object>
<object class="GtkImage" id="pauseImg">
<property name="visible">True</property>
<property name="can_focus">False</property>
@ -60,6 +70,16 @@
<property name="can_focus">False</property>
<property name="icon_name">media-playback-stop</property>
</object>
<object class="GtkImage" id="toggleAudioImg">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">audio-volume-muted</property>
</object>
<object class="GtkImage" id="toggleSubtitleImg">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">document-page-setup</property>
</object>
<object class="GtkImage" id="volDownImg">
<property name="visible">True</property>
<property name="can_focus">False</property>
@ -137,8 +157,8 @@
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Titel zurück</property>
<property name="image">prevImg</property>
<accelerator key="less" signal="clicked"/>
<accelerator key="b" signal="clicked"/>
<accelerator key="less" signal="clicked"/>
</object>
<packing>
<property name="expand">True</property>
@ -152,9 +172,9 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">jumpBackImg</property>
<accelerator key="a" signal="clicked"/>
<accelerator key="Left" signal="clicked" modifiers="GDK_SHIFT_MASK"/>
<accelerator key="Left" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="Left" signal="clicked" modifiers="GDK_SHIFT_MASK"/>
<accelerator key="a" signal="clicked"/>
</object>
<packing>
<property name="expand">True</property>
@ -169,8 +189,8 @@
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Pause</property>
<property name="image">pauseImg</property>
<accelerator key="p" signal="clicked"/>
<accelerator key="space" signal="clicked"/>
<accelerator key="p" signal="clicked"/>
</object>
<packing>
<property name="expand">True</property>
@ -199,9 +219,9 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">jumpForwardBt</property>
<accelerator key="d" signal="clicked"/>
<accelerator key="Right" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="Right" signal="clicked" modifiers="GDK_SHIFT_MASK"/>
<accelerator key="Right" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="d" signal="clicked"/>
</object>
<packing>
<property name="expand">True</property>
@ -216,8 +236,8 @@
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Titel überspringen</property>
<property name="image">nextImg</property>
<accelerator key="greater" signal="clicked"/>
<accelerator key="n" signal="clicked"/>
<accelerator key="greater" signal="clicked"/>
</object>
<packing>
<property name="expand">True</property>
@ -327,9 +347,9 @@
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Vollbild</property>
<property name="image">fullscreenImg</property>
<accelerator key="F11" signal="clicked"/>
<accelerator key="F5" signal="clicked"/>
<accelerator key="f" signal="clicked"/>
<accelerator key="F5" signal="clicked"/>
<accelerator key="F11" signal="clicked"/>
</object>
<packing>
<property name="expand">True</property>
@ -337,6 +357,62 @@
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkToggleButton" id="toggleAudioBtn">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">toggleAudioImg</property>
<accelerator key="m" signal="clicked"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkToggleButton" id="nextSubtitleBtn">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">nextSubtitleImg</property>
<accelerator key="w" signal="clicked"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkButton" id="nextAudioBtn">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">nextAudioImg</property>
<accelerator key="k" signal="clicked"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">6</property>
</packing>
</child>
<child>
<object class="GtkButton" id="toggleSubtitleBtn">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">toggleSubtitleImg</property>
<accelerator key="s" signal="clicked"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">7</property>
</packing>
</child>
<child>
<object class="GtkToggleButton" id="playlistBtn">
<property name="visible">True</property>
@ -347,7 +423,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">5</property>
<property name="position">8</property>
</packing>
</child>
<child>
@ -362,7 +438,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">5</property>
<property name="position">9</property>
</packing>
</child>
</object>

19
dbuscontrol.sh

@ -100,7 +100,24 @@ togglesubtitles)
hidesubtitles)
dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:30 >/dev/null
;;
prevaudio)
dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:6 >/dev/null
;;
nextaudio)
dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:7 >/dev/null
;;
nextsubtitle)
dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:11 >/dev/null
;;
prevsubtitle)
dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:10 >/dev/null
;;
delaysubtitleINC)
dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:14 >/dev/null
;;
delaysubtitleDEC)
dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:13 >/dev/null
;;
showsubtitles)
dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:31 >/dev/null
;;

7
src/gtplay.py

@ -40,8 +40,11 @@ except:
addr = ('localhost', port)
for v in videolist:
print ("Sending: videoadd",str(v))
s.sendto (("videoadd,"+str(v)).encode("utf-8"), addr)
sys.exit(0)
if v.type == "live" :
s.sendto ((("liveadd,%s,%s"%(v.name, v.url))).encode("utf-8"), addr)
else:
s.sendto ((("videoadd,%s,%s"%(v.name, v.url))).encode("utf-8"), addr)
sys.exit(0);
#try:
if 1:

33
src/mainWindow.py

@ -63,6 +63,7 @@ class MainWindow ( object ):
# set callbacks for buttons, dials, switches and toggles
va=self.builder.get_object ( "videoArea" )
va.connect ( "realize", self.videoArea_realize, self );
va.connect ( "draw", self.videoArea_draw );
va.add_events ( Gdk.EventType.CONFIGURE );
va.connect ( "configure-event", self.resizeCb );
self.builder.get_object ( "pauseBtn" ).connect ( "clicked", self.pauseTrigger );
@ -77,7 +78,12 @@ class MainWindow ( object ):
self.builder.get_object ( "gtplayer" ).connect ( "button-press-event", self.progressBarTrigger );
self.builder.get_object ( "jumpForwardBtn" ).connect ( "clicked", self.jump, 10 );
self.builder.get_object ( "jumpBackBtn" ).connect ( "clicked", self.jump, -10 );
self.builder.get_object ( "hideBtn" ).connect ("clicked", self.HideBtnTrigger )
self.builder.get_object ( "hideBtn" ).connect ("clicked", self.HideBtnTrigger );
self.builder.get_object ( "nextSubtitleBtn" ).connect ("clicked", self.nextSubtitleTrigger, 1 );
self.builder.get_object ( "nextAudioBtn" ).connect ( "clicked", self.nextAudioTrigger, 1 );
self.builder.get_object ( "toggleSubtitleBtn" ).connect ("clicked", self.toggleSubtitleTrigger );
self.builder.get_object ( "toggleAudioBtn" ).connect ("clicked", self.toggleAudioTrigger );
# initialise the playlistView
self.playlistBtnTrigger(None)
@ -196,6 +202,18 @@ class MainWindow ( object ):
self.builder.get_object("gtplayer").fullscreen();
self.fullscreen = not self.fullscreen;
def nextSubtitleTrigger ( self, widget, data=None ):
self.player.nextSubtitle ( 1 );
def nextAudioTrigger ( self, widget, data=None ):
self.player.nextAudio ( 1 );
def toggleSubtitleTrigger ( self, widget, data=None ):
self.player.toggleSubtitle ();
def toggleAudioTrigger ( self, widget, data=None ):
self.player.toggleAudio ();
## Callback for the next-button
def nextTrigger ( self, widget, data=None ):
self.started = False;
@ -330,6 +348,13 @@ class MainWindow ( object ):
for mi in m[2:]:
url = url + mi + ","
v = Video ( title, url[:-1] )
elif ( m[0] == "liveadd" ):
m = msg.split ( "," );
title = m[1];
url = ""
for mi in m[2:]:
url = url + mi + ","
v = Video ( title, url[:-1], "live" )
else:
print ("Command not part of protocol: %s"%m[0] );
else:
@ -371,3 +396,9 @@ class MainWindow ( object ):
self.player = OMXPlayer ( self, self.playlist, widget );
self.player.start ();
self.setTitle ();
def videoArea_draw ( self, widget, cr ):
cr.set_source_rgb(0, 0, 0)
a = widget.get_allocation();
cr.rectangle(0,0, a.width, a.height)
cr.fill()

40
src/omxplayer.py

@ -5,6 +5,8 @@ from genericThread import *
from player import *
import playlist
from threading import Event
import getpass
import os
@ -24,6 +26,7 @@ from gi.repository import GLib, Gtk
omxrunning = False;
dbusctrl = os.path.dirname(__file__) + "/../dbuscontrol.sh"
destroyOMX = Event();
class OMXCommunicationException ( Exception ):
pass
@ -38,6 +41,7 @@ class Argument ( object ):
def OMXPlayerThread ( args=None ):
global omxrunning
global destroyOMX
omxrunning = True;
parameters = [];
omx = None
@ -69,6 +73,7 @@ class OMXState ():
self.hidden = False
self.fresh = False;
self.volume = 1.0;
self.muted = False;
self.playslive = False;
class OMXPlayer ( Player ):
@ -76,8 +81,6 @@ class OMXPlayer ( Player ):
def __init__ ( self, mainwnd, playlist, videoArea ):
self.initOMXEnv()
#print (os.environ);
self.mainwnd = mainwnd
## Playlist object
self.playlist = playlist;
@ -327,6 +330,34 @@ class OMXPlayer ( Player ):
def isHidden( self ):
return self.omxstate.hidden
def delaySubtitle ( self, direction ):
if direction > 0:
self.omxshsend ( "delaysubtitleINC" );
elif direction < 0:
self.omxshsend ( "delaysubtitleDEC" );
def nextAudio ( self, direction ):
if direction > 0:
self.omxshsend ( "nextaudio" );
elif direction < 0:
self.omxshsend ( "prevaudio" );
def nextSubtitle ( self, direction ):
if direction > 0:
self.omxshsend ( "nextsubtitle" );
elif direction < 0:
self.omxshsend ( "prevsubtitle" );
def toggleSubtitle ( self ):
self.omxshsend ( "togglesubtitles" )
def toggleAudio ( self ):
self.omxstate.muted = not self.omxstate.muted;
if self.omxstate.muted:
self.volume ( 0 );
else:
self.volume ( self.omxstate.volume )
def GtkWindowObserver ( self, args=None ):
global omxrunning
print ("Starting OMX Player Observer")
@ -366,7 +397,10 @@ class OMXPlayer ( Player ):
if self.omxstate.hidden:
self.omxshsend_reliable ( "hidevideo" );
self.volume ( self.omxstate.volume );
if self.omxstate.muted:
self.volume ( 0 );
else:
self.volume ( self.omxstate.volume )
self.omxstate.fresh = False;
except:
print ("reset props: OMX not ready yet");

2
src/playlist.py

@ -210,7 +210,7 @@ class Playlist ( object ):
with open(video.url) as f:
txt = f.readlines();
for t in txt:
r = self.expandEntry ( Video("", t) );
r = self.expandEntry ( Video("", t, origin = video["url"]) );
if (type(r) is list):
res += r;
else:

Loading…
Cancel
Save