forked from Mediacore/mediaserver

Added looping functions Removed separate quickplayer. Quickplayer is now integrated in normal player
66 lines
No EOL
1.9 KiB
Python
Executable file
66 lines
No EOL
1.9 KiB
Python
Executable file
# perform gstreamer imports (python3 style)
|
|
import gi
|
|
gi.require_version('Gst','1.0')
|
|
|
|
from gi.repository import GObject
|
|
|
|
# import from this module
|
|
from monitoredplayer import MonitoredPlayer
|
|
|
|
class QuickPlayer(GObject.GObject):
|
|
|
|
def __init__(self):
|
|
GObject.GObject.__init__(self)
|
|
self.player = MonitoredPlayer()
|
|
self._duration = -1;
|
|
self.player.connect("playback-ready",self.onReady)
|
|
self.player.connect("playback-error",self.onError)
|
|
|
|
|
|
# Calling functions for file
|
|
def playfor(self,file,duration):
|
|
if duration > 0: # not much point in wasting system resources otherwise
|
|
self._duration = duration
|
|
self.player.load(file)
|
|
elif duration < 0: # same as normal play
|
|
self.play(file)
|
|
|
|
def play(self,file):
|
|
self._duration = -1;
|
|
self.player.load(file)
|
|
|
|
# Calling functions for urls
|
|
def playurlfor(self,url,duration):
|
|
if duration > 0: # not much point in wasting system resources otherwise
|
|
self._duration = duration
|
|
self.player.load_uri(url)
|
|
elif duration < 0: # same as normal play
|
|
self.playurl(url)
|
|
|
|
def playurl(self,url):
|
|
self._duration = -1;
|
|
self.player.load_uri(url)
|
|
|
|
# stop function
|
|
def stop(self):
|
|
self._duration = -1
|
|
self.player.stop()
|
|
|
|
def onReady(self,player,file,tags):
|
|
print "Quickplay loaded: {0}".format(file)
|
|
for tag in tags:
|
|
print " {0}: {1}".format(tag,tags[tag])
|
|
if self._duration > 0:
|
|
self.player.playfor(self._duration)
|
|
elif self._duration < 0:
|
|
self.player.play()
|
|
|
|
def onError(self,player,player_state,error,debug):
|
|
print "Quickplay error during " + player_state + ":"
|
|
print " " + error
|
|
print " "
|
|
print " " + debug
|
|
|
|
|
|
GObject.type_register(QuickPlayer)
|
|
|